diff --git a/google-cloud-storage/pom.xml b/google-cloud-storage/pom.xml index 95511d41366e..329d7055794a 100644 --- a/google-cloud-storage/pom.xml +++ b/google-cloud-storage/pom.xml @@ -30,7 +30,7 @@ com.google.apis google-api-services-storage - v1-rev108-1.22.0 + v1-rev114-1.23.0 compile diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java index 3cd352d982ad..0a6e2a6f6c4d 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java @@ -764,6 +764,15 @@ public static BucketListOption prefix(String prefix) { return new BucketListOption(StorageRpc.Option.PREFIX, prefix); } + /** + * Returns an option for bucket's billing user project. This option is only used by the buckets with + * 'requester_pays' flag. + */ + @GcpLaunchStage.Alpha + public static BucketListOption userProject(String userProject) { + return new BucketListOption(StorageRpc.Option.USER_PROJECT, userProject); + } + /** * Returns an option to specify the bucket's fields to be returned by the RPC call. If this * option is not provided all bucket's fields are returned. {@code BucketListOption.fields}) can @@ -824,6 +833,15 @@ public static BlobListOption currentDirectory() { return new BlobListOption(StorageRpc.Option.DELIMITER, true); } + /** + * Returns an option for bucket's billing user project. This option is only used by the buckets with + * 'requester_pays' flag. + */ + @GcpLaunchStage.Alpha + public static BlobListOption userProject(String userProject) { + return new BlobListOption(StorageRpc.Option.USER_PROJECT, userProject); + } + /** * If set to {@code true}, lists all versions of a blob. The default is {@code false}. * diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java index 5e3aeff3acaf..f83f8b3ed017 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java @@ -252,6 +252,7 @@ public Tuple> list(Map options) { .setMaxResults(Option.MAX_RESULTS.getLong(options)) .setPageToken(Option.PAGE_TOKEN.getString(options)) .setFields(Option.FIELDS.getString(options)) + .setUserProject(Option.USER_PROJECT.getString(options)) .execute(); return Tuple.>of(buckets.getNextPageToken(), buckets.getItems()); } catch (IOException ex) { diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java index c6854550e461..c6dd6aae9721 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java @@ -400,6 +400,30 @@ public void testListBlobsEmptySelectedFields() throws InterruptedException { assertTrue(blobSet.contains(remoteBlob.getName())); assertNull(remoteBlob.getContentType()); } + + // Test listing a Requester Pays bucket. + Bucket remoteBucket = storage.get(BUCKET, Storage.BucketGetOption.fields(BucketField.ID)); + assertNull(remoteBucket.requesterPays()); + remoteBucket = remoteBucket.toBuilder().setRequesterPays(true).build(); + Bucket updatedBucket = storage.update(remoteBucket); + assertTrue(updatedBucket.requesterPays()); + String projectId = remoteStorageHelper.getOptions().getProjectId(); + try { + page = storage.list(BUCKET, + Storage.BlobListOption.prefix("test-list-blobs-empty-selected-fields-blob"), + Storage.BlobListOption.fields(), + Storage.BlobListOption.userProject("fakeBillingProjectId")); + fail("Expected bad user project error."); + } catch (StorageException e) { + assertTrue(e.getMessage().contains("User project specified in the request is invalid")); + } + while (Iterators.size(page.iterateAll().iterator()) != 2) { + Thread.sleep(500); + page = storage.list(BUCKET, + Storage.BlobListOption.prefix("test-list-blobs-empty-selected-fields-blob"), + Storage.BlobListOption.fields(), + Storage.BlobListOption.userProject(projectId)); + } assertTrue(remoteBlob1.delete()); assertTrue(remoteBlob2.delete()); } @@ -1519,4 +1543,22 @@ public void testUpdateBucketRequesterPays() { assertArrayEquals(BLOB_BYTE_CONTENT, readBytes); assertTrue(remoteBlob.delete()); } + + @Test + public void testListBucketRequesterPaysFails() throws InterruptedException { + String projectId = remoteStorageHelper.getOptions().getProjectId(); + Iterator bucketIterator = storage.list(Storage.BucketListOption.prefix(BUCKET), + Storage.BucketListOption.fields(), Storage.BucketListOption.userProject(projectId)).iterateAll().iterator(); + while (!bucketIterator.hasNext()) { + Thread.sleep(500); + bucketIterator = storage.list(Storage.BucketListOption.prefix(BUCKET), + Storage.BucketListOption.fields()).iterateAll().iterator(); + } + while (bucketIterator.hasNext()) { + Bucket remoteBucket = bucketIterator.next(); + assertTrue(remoteBucket.getName().startsWith(BUCKET)); + assertNull(remoteBucket.getCreateTime()); + assertNull(remoteBucket.getSelfLink()); + } + } } diff --git a/pom.xml b/pom.xml index b45b999803cd..4d0b81b8430b 100644 --- a/pom.xml +++ b/pom.xml @@ -137,7 +137,7 @@ github google-cloud - 1.22.0 + 1.23.0 1.1.0 1.9.1 @@ -147,7 +147,7 @@ 1.7.0 2.0.6.Final 20.0 - 1.22.0 + 1.23.0 3.4.0 3.4 @@ -772,7 +772,7 @@ com.google.oauth-client google-oauth-client - 1.22.0 + 1.23.0 com.google.api-client