diff --git a/README.md b/README.md index 5f38caabf1..b1363426ae 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,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.5.1' +implementation 'com.google.cloud:google-cloud-storage:2.6.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "2.5.1" +libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "2.6.0" ``` ## Authentication @@ -240,9 +240,11 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-storage/tree/ | Change Default Storage Class | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/ChangeDefaultStorageClass.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/ChangeDefaultStorageClass.java) | | Configure Bucket Cors | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/ConfigureBucketCors.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/ConfigureBucketCors.java) | | 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 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 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) | +| Delete Bucket Pub Sub Notification | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucketPubSubNotification.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/DeleteBucketPubSubNotification.java) | | Disable Bucket Versioning | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/DisableBucketVersioning.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/DisableBucketVersioning.java) | | Disable Default Event Based Hold | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/DisableDefaultEventBasedHold.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/DisableDefaultEventBasedHold.java) | | Disable Lifecycle Management | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/DisableLifecycleManagement.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/DisableLifecycleManagement.java) | @@ -262,10 +264,12 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-storage/tree/ | Get Uniform Bucket Level Access | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/GetUniformBucketLevelAccess.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/GetUniformBucketLevelAccess.java) | | List Bucket Iam Members | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/ListBucketIamMembers.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/ListBucketIamMembers.java) | | List Buckets | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/ListBuckets.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/ListBuckets.java) | +| List Pub Sub Notifications | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/ListPubSubNotifications.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/ListPubSubNotifications.java) | | Lock Retention Policy | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/LockRetentionPolicy.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/LockRetentionPolicy.java) | | Make Bucket Public | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/MakeBucketPublic.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/MakeBucketPublic.java) | | Print Bucket Acl | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/PrintBucketAcl.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/PrintBucketAcl.java) | | Print Bucket Acl Filter By User | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/PrintBucketAclFilterByUser.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/PrintBucketAclFilterByUser.java) | +| Print Pub Sub Notification | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/PrintPubSubNotification.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/PrintPubSubNotification.java) | | Remove Bucket Cors | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/RemoveBucketCors.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/RemoveBucketCors.java) | | Remove Bucket Default Kms Key | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/RemoveBucketDefaultKmsKey.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/RemoveBucketDefaultKmsKey.java) | | Remove Bucket Default Owner | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/RemoveBucketDefaultOwner.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/RemoveBucketDefaultOwner.java) | diff --git a/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java b/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java index d98727497b..51907d44ce 100644 --- a/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java +++ b/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java @@ -25,10 +25,10 @@ import com.google.cloud.storage.StorageOptions; import java.util.Map; - public class CreateBucketPubSubNotification { - public static void createBucketPubSubNotification(String bucketName, + public static void createBucketPubSubNotification( + String bucketName, String topicName, Map customAttributes, EventType[] eventTypes, @@ -58,16 +58,17 @@ public static void createBucketPubSubNotification(String bucketName, // String etag = "etag-value"; Storage storage = StorageOptions.newBuilder().build().getService(); - NotificationInfo notificationInfo = NotificationInfo.newBuilder(topicName) - .setEtag(etag) - .setCustomAttributes(customAttributes) - .setSelfLink(selfLink) - .setEventTypes(eventTypes) - .setObjectNamePrefix(objectNamePrefix) - .setPayloadFormat(payloadFormat) - .build(); + NotificationInfo notificationInfo = + NotificationInfo.newBuilder(topicName) + .setEtag(etag) + .setCustomAttributes(customAttributes) + .setSelfLink(selfLink) + .setEventTypes(eventTypes) + .setObjectNamePrefix(objectNamePrefix) + .setPayloadFormat(payloadFormat) + .build(); Notification notification = storage.createNotification(bucketName, notificationInfo); System.out.println("Successfully created notification for topic " + notification.getTopic()); } } -// [END storage_create_bucket_notifications] \ No newline at end of file +// [END storage_create_bucket_notifications] diff --git a/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucketPubSubNotification.java b/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucketPubSubNotification.java index b6e9ccbfed..dd59e2e189 100644 --- a/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucketPubSubNotification.java +++ b/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucketPubSubNotification.java @@ -17,11 +17,9 @@ package com.example.storage.bucket; // [START storage_delete_bucket_notification] -import com.google.cloud.storage.Bucket; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; - public class DeleteBucketPubSubNotification { public static void deleteBucketPubSubNotification(String bucketName, String notificationId) { @@ -40,4 +38,4 @@ public static void deleteBucketPubSubNotification(String bucketName, String noti } } } -// [END storage_delete_bucket_notification] \ No newline at end of file +// [END storage_delete_bucket_notification] diff --git a/samples/snippets/src/main/java/com/example/storage/bucket/ListPubSubNotifications.java b/samples/snippets/src/main/java/com/example/storage/bucket/ListPubSubNotifications.java index 48f2e2df87..b3fb614f8b 100644 --- a/samples/snippets/src/main/java/com/example/storage/bucket/ListPubSubNotifications.java +++ b/samples/snippets/src/main/java/com/example/storage/bucket/ListPubSubNotifications.java @@ -17,13 +17,11 @@ package com.example.storage.bucket; // [START storage_list_bucket_notifications] -import com.google.cloud.storage.Bucket; import com.google.cloud.storage.Notification; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; import java.util.List; - public class ListPubSubNotifications { public static void listPubSubNotifications(String bucketName) { @@ -38,4 +36,4 @@ public static void listPubSubNotifications(String bucketName) { } } } -// [END storage_list_bucket_notifications] \ No newline at end of file +// [END storage_list_bucket_notifications] diff --git a/samples/snippets/src/main/java/com/example/storage/bucket/PrintPubSubNotification.java b/samples/snippets/src/main/java/com/example/storage/bucket/PrintPubSubNotification.java index dbb8811bd7..083a0b551a 100644 --- a/samples/snippets/src/main/java/com/example/storage/bucket/PrintPubSubNotification.java +++ b/samples/snippets/src/main/java/com/example/storage/bucket/PrintPubSubNotification.java @@ -17,19 +17,16 @@ package com.example.storage.bucket; // [START storage_print_pubsub_bucket_notification] -import com.google.cloud.storage.Bucket; import com.google.cloud.storage.Notification; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; -import java.util.List; - public class PrintPubSubNotification { public static void printPubSubNotification(String bucketName, String notificationId) { // The ID to give your GCS bucket // String bucketName = "your-unique-bucket-name"; - + // The Pub/Sub topic you would like to find // String notificationId = "your-unique-notification-id" @@ -39,4 +36,4 @@ public static void printPubSubNotification(String bucketName, String notificatio "Found notification " + notification.getTopic() + " for bucket " + bucketName); } } -// [END storage_print_pubsub_bucket_notification] \ No newline at end of file +// [END storage_print_pubsub_bucket_notification] diff --git a/samples/snippets/src/test/java/com/example/storage/bucket/CreateBucketPubSubNotificationTest.java b/samples/snippets/src/test/java/com/example/storage/bucket/CreateBucketPubSubNotificationTest.java index e34bbcca2c..c36a5d85a2 100644 --- a/samples/snippets/src/test/java/com/example/storage/bucket/CreateBucketPubSubNotificationTest.java +++ b/samples/snippets/src/test/java/com/example/storage/bucket/CreateBucketPubSubNotificationTest.java @@ -23,7 +23,6 @@ import com.google.cloud.pubsub.v1.TopicAdminClient; import com.google.cloud.storage.Notification; import com.google.cloud.storage.NotificationInfo.EventType; -import com.google.cloud.storage.NotificationInfo.PayloadFormat; import com.google.common.collect.ImmutableMap; import com.google.iam.v1.Binding; import com.google.iam.v1.GetIamPolicyRequest; @@ -45,7 +44,7 @@ public class CreateBucketPubSubNotificationTest extends TestBase { private static final String SELF_LINK = "http://storage/b/n"; private static final String OBJECT_NAME_PREFIX = "index.html"; private static final EventType[] EVENT_TYPES = { - EventType.OBJECT_FINALIZE, EventType.OBJECT_METADATA_UPDATE + EventType.OBJECT_FINALIZE, EventType.OBJECT_METADATA_UPDATE }; private static TopicAdminClient topicAdminClient; @@ -94,5 +93,4 @@ public void testCreateBucketPubSubNotification() { ETAG); assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(TOPIC); } - -} \ No newline at end of file +} diff --git a/samples/snippets/src/test/java/com/example/storage/bucket/DeleteBucketPubSubNotificationTest.java b/samples/snippets/src/test/java/com/example/storage/bucket/DeleteBucketPubSubNotificationTest.java index 2abbad233f..e094f33469 100644 --- a/samples/snippets/src/test/java/com/example/storage/bucket/DeleteBucketPubSubNotificationTest.java +++ b/samples/snippets/src/test/java/com/example/storage/bucket/DeleteBucketPubSubNotificationTest.java @@ -41,10 +41,11 @@ public class DeleteBucketPubSubNotificationTest extends TestBase { private static final String PROJECT = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String TOPIC = String.format("projects/%s/topics/new-topic-delete", PROJECT); private static TopicAdminClient topicAdminClient; - private static final NotificationInfo notificationInfo = NotificationInfo.newBuilder(TOPIC) - .setCustomAttributes(CUSTOM_ATTRIBUTES) - .setPayloadFormat(PAYLOAD_FORMAT) - .build(); + private static final NotificationInfo notificationInfo = + NotificationInfo.newBuilder(TOPIC) + .setCustomAttributes(CUSTOM_ATTRIBUTES) + .setPayloadFormat(PAYLOAD_FORMAT) + .build(); @BeforeClass public static void configureTopicAdminClient() throws IOException { @@ -82,10 +83,9 @@ public void testDeleteBucketPubSubNotification() { Notification notification = storage.createNotification(bucketName, notificationInfo); com.example.storage.bucket.DeleteBucketPubSubNotification.deleteBucketPubSubNotification( - bucketName, - notification.getNotificationId()); - assertThat(stdOut.getCapturedOutputAsUtf8String()).contains( - "Successfully deleted notification"); + bucketName, notification.getNotificationId()); + assertThat(stdOut.getCapturedOutputAsUtf8String()) + .contains("Successfully deleted notification"); } @Test @@ -98,9 +98,7 @@ public void testNotificationNotFound() { storage.deleteNotification(bucketName, notification.getNotificationId()); // Now try to delete again. com.example.storage.bucket.DeleteBucketPubSubNotification.deleteBucketPubSubNotification( - bucketName, - notification.getNotificationId()); + bucketName, notification.getNotificationId()); assertThat(stdOut.getCapturedOutputAsUtf8String()).contains("Failed to find notification"); } - -} \ No newline at end of file +} diff --git a/samples/snippets/src/test/java/com/example/storage/bucket/ListPubSubNotificationsTest.java b/samples/snippets/src/test/java/com/example/storage/bucket/ListPubSubNotificationsTest.java index 5c74ef3a2c..c7dee85472 100644 --- a/samples/snippets/src/test/java/com/example/storage/bucket/ListPubSubNotificationsTest.java +++ b/samples/snippets/src/test/java/com/example/storage/bucket/ListPubSubNotificationsTest.java @@ -85,5 +85,4 @@ public void testListBucketPubSubNotification() { ListPubSubNotifications.listPubSubNotifications(bucketName); assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(TOPIC); } - -} \ No newline at end of file +} diff --git a/samples/snippets/src/test/java/com/example/storage/bucket/PrintPubSubNotificationTest.java b/samples/snippets/src/test/java/com/example/storage/bucket/PrintPubSubNotificationTest.java index f9eaf2c3cf..05526675ff 100644 --- a/samples/snippets/src/test/java/com/example/storage/bucket/PrintPubSubNotificationTest.java +++ b/samples/snippets/src/test/java/com/example/storage/bucket/PrintPubSubNotificationTest.java @@ -85,5 +85,4 @@ public void testPrintBucketPubSubNotification() { PrintPubSubNotification.printPubSubNotification(bucketName, notification.getNotificationId()); assertThat(stdOut.getCapturedOutputAsUtf8String()).contains(TOPIC); } - -} \ No newline at end of file +}