From a42e53fc3fb9edfd24c6df1da58546fe08954615 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 15 Feb 2024 21:44:39 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20post-p?= =?UTF-8?q?rocessor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 8 ++- .../CreateBucketWithObjectRetention.java | 28 ++++---- .../object/SetObjectRetentionPolicy.java | 72 ++++++++++--------- .../com/example/storage/ITBucketSnippets.java | 2 - .../com/example/storage/ITObjectSnippets.java | 11 ++- 5 files changed, 65 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 1bfe56831a..f050fdc9a3 100644 --- a/README.md +++ b/README.md @@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-storage' If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-storage:2.33.0' +implementation 'com.google.cloud:google-cloud-storage:2.34.0' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "2.33.0" +libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "2.34.0" ``` @@ -237,6 +237,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-storage/tree/ | Create Bucket | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucket.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucket.java) | | Create Bucket Dual Region | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketDualRegion.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketDualRegion.java) | | Create Bucket Pub Sub Notification | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java) | +| Create Bucket With Object Retention | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithObjectRetention.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithObjectRetention.java) | | Create Bucket With Storage Class And Location | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithStorageClassAndLocation.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithStorageClassAndLocation.java) | | Create Bucket With Turbo Replication | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithTurboReplication.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithTurboReplication.java) | | Delete Bucket | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucket.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucket.java) | @@ -322,6 +323,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-storage/tree/ | Rotate Object Encryption Key | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/RotateObjectEncryptionKey.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/RotateObjectEncryptionKey.java) | | Set Event Based Hold | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/SetEventBasedHold.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/SetEventBasedHold.java) | | Set Object Metadata | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/SetObjectMetadata.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/SetObjectMetadata.java) | +| Set Object Retention Policy | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/SetObjectRetentionPolicy.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/SetObjectRetentionPolicy.java) | | Set Temporary Hold | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/SetTemporaryHold.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/SetTemporaryHold.java) | | Stream Object Download | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/StreamObjectDownload.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/StreamObjectDownload.java) | | Stream Object Upload | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/StreamObjectUpload.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/StreamObjectUpload.java) | @@ -428,7 +430,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-storage/java11.html [stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-storage.svg -[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-storage/2.33.0 +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-storage/2.34.0 [authentication]: https://github.com/googleapis/google-cloud-java#authentication [auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes [predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles diff --git a/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithObjectRetention.java b/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithObjectRetention.java index b5f405b0e5..8d12ef23ca 100644 --- a/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithObjectRetention.java +++ b/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithObjectRetention.java @@ -23,23 +23,25 @@ import com.google.cloud.storage.StorageOptions; public class CreateBucketWithObjectRetention { - public static void createBucketWithObjectRetention(String projectId, String bucketName) { - // The ID of your GCP project - // String projectId = "your-project-id"; + public static void createBucketWithObjectRetention(String projectId, String bucketName) { + // The ID of your GCP project + // String projectId = "your-project-id"; - // The ID to give your GCS bucket - // String bucketName = "your-unique-bucket-name"; + // The ID to give your GCS bucket + // String bucketName = "your-unique-bucket-name"; - Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); + Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); - Bucket bucket = storage.create(BucketInfo.of(bucketName), Storage.BucketTargetOption.enableObjectRetention(true)); + Bucket bucket = + storage.create( + BucketInfo.of(bucketName), Storage.BucketTargetOption.enableObjectRetention(true)); - System.out.println( - "Created bucket " - + bucket.getName() - + " with object retention enabled setting: " - + bucket.getObjectRetention().getMode().toString()); - } + System.out.println( + "Created bucket " + + bucket.getName() + + " with object retention enabled setting: " + + bucket.getObjectRetention().getMode().toString()); + } } // [END storage_create_bucket_with_object_retention] diff --git a/samples/snippets/src/main/java/com/example/storage/object/SetObjectRetentionPolicy.java b/samples/snippets/src/main/java/com/example/storage/object/SetObjectRetentionPolicy.java index 4cffb475c8..2cadd9f4c5 100644 --- a/samples/snippets/src/main/java/com/example/storage/object/SetObjectRetentionPolicy.java +++ b/samples/snippets/src/main/java/com/example/storage/object/SetObjectRetentionPolicy.java @@ -18,6 +18,8 @@ // [START storage_set_object_retention_policy] +import static java.time.OffsetDateTime.now; + import com.google.cloud.storage.Blob; import com.google.cloud.storage.BlobId; import com.google.cloud.storage.BlobInfo.Retention; @@ -25,49 +27,49 @@ import com.google.cloud.storage.StorageException; import com.google.cloud.storage.StorageOptions; - -import static java.time.OffsetDateTime.now; - public class SetObjectRetentionPolicy { - public static void setObjectRetentionPolicy(String projectId, String bucketName, String objectName) - throws StorageException { - // The ID of your GCP project - // String projectId = "your-project-id"; - - // The ID of your GCS bucket that has object retention enabled - // String bucketName = "your-unique-bucket-name"; + public static void setObjectRetentionPolicy( + String projectId, String bucketName, String objectName) throws StorageException { + // The ID of your GCP project + // String projectId = "your-project-id"; - // The ID of your GCS object - // String objectName = "your-object-name"; + // The ID of your GCS bucket that has object retention enabled + // String bucketName = "your-unique-bucket-name"; - Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); - BlobId blobId = BlobId.of(bucketName, objectName); - Blob blob = storage.get(blobId); - if (blob == null) { - System.out.println("The object " + objectName + " was not found in " + bucketName); - return; - } + // The ID of your GCS object + // String objectName = "your-object-name"; - Blob updated = blob.toBuilder().setRetention(Retention.newBuilder() - .setMode(Retention.Mode.UNLOCKED) - .setRetainUntilTime(now().plusDays(10)) - .build()) - .build() - .update(); + Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); + BlobId blobId = BlobId.of(bucketName, objectName); + Blob blob = storage.get(blobId); + if (blob == null) { + System.out.println("The object " + objectName + " was not found in " + bucketName); + return; + } - System.out.println("Retention policy for object " + objectName + " was set to:"); - System.out.println(updated.getRetention().toString()); + Blob updated = + blob.toBuilder() + .setRetention( + Retention.newBuilder() + .setMode(Retention.Mode.UNLOCKED) + .setRetainUntilTime(now().plusDays(10)) + .build()) + .build() + .update(); - // To modify an existing policy on an Unlocked object, pass in the override parameter - blob.toBuilder().setRetention(updated.getRetention() - .toBuilder().setRetainUntilTime(now().plusDays(9)).build()) - .build() - .update(Storage.BlobTargetOption.overrideUnlockedRetention(true)); + System.out.println("Retention policy for object " + objectName + " was set to:"); + System.out.println(updated.getRetention().toString()); + // To modify an existing policy on an Unlocked object, pass in the override parameter + blob.toBuilder() + .setRetention( + updated.getRetention().toBuilder().setRetainUntilTime(now().plusDays(9)).build()) + .build() + .update(Storage.BlobTargetOption.overrideUnlockedRetention(true)); - System.out.println("Retention policy for object " + objectName + " was updated to:"); - System.out.println(storage.get(blobId).getRetention().toString()); - } + System.out.println("Retention policy for object " + objectName + " was updated to:"); + System.out.println(storage.get(blobId).getRetention().toString()); + } } // [START storage_set_object_retention_policy] diff --git a/samples/snippets/src/test/java/com/example/storage/ITBucketSnippets.java b/samples/snippets/src/test/java/com/example/storage/ITBucketSnippets.java index 19562c843c..449903389c 100644 --- a/samples/snippets/src/test/java/com/example/storage/ITBucketSnippets.java +++ b/samples/snippets/src/test/java/com/example/storage/ITBucketSnippets.java @@ -700,7 +700,5 @@ public void testCreateBucketWithObjectRetention() { } finally { storage.delete(tempBucket); } - - } } diff --git a/samples/snippets/src/test/java/com/example/storage/ITObjectSnippets.java b/samples/snippets/src/test/java/com/example/storage/ITObjectSnippets.java index 10c729e62f..c3e66adc32 100644 --- a/samples/snippets/src/test/java/com/example/storage/ITObjectSnippets.java +++ b/samples/snippets/src/test/java/com/example/storage/ITObjectSnippets.java @@ -58,7 +58,6 @@ import com.google.cloud.storage.Blob; import com.google.cloud.storage.BlobId; import com.google.cloud.storage.BlobInfo; -import com.google.cloud.storage.Bucket; import com.google.cloud.storage.BucketInfo; import com.google.cloud.storage.Storage; import com.google.cloud.storage.Storage.BlobListOption; @@ -440,7 +439,8 @@ public void testBatchSetObjectMetadata() { @Test public void testSetObjectRetentionPolicy() { String tempBucket = RemoteStorageHelper.generateBucketName(); - storage.create(BucketInfo.of(tempBucket), Storage.BucketTargetOption.enableObjectRetention(true)); + storage.create( + BucketInfo.of(tempBucket), Storage.BucketTargetOption.enableObjectRetention(true)); String retentionBlob = "retentionblob"; storage.create(BlobInfo.newBuilder(tempBucket, retentionBlob).build()); assertNull(storage.get(tempBucket, retentionBlob).getRetention()); @@ -448,7 +448,12 @@ public void testSetObjectRetentionPolicy() { SetObjectRetentionPolicy.setObjectRetentionPolicy(PROJECT_ID, tempBucket, retentionBlob); assertNotNull(storage.get(tempBucket, retentionBlob).getRetention()); } finally { - storage.get(tempBucket, retentionBlob).toBuilder().setRetention(null).build().update(Storage.BlobTargetOption.overrideUnlockedRetention(true)); + storage + .get(tempBucket, retentionBlob) + .toBuilder() + .setRetention(null) + .build() + .update(Storage.BlobTargetOption.overrideUnlockedRetention(true)); storage.delete(tempBucket, retentionBlob); storage.delete(tempBucket); }