/** Example of listing the ACL entries for a blob. */ // [TARGET listAcls(String)] // [VARIABLE "my_unique_bucket"] public List<Acl> listBucketAcls(String bucketName) { // [START listBucketAcls] List<Acl> acls = storage.listAcls(bucketName); for (Acl acl : acls) { // do something with ACL entry } // [END listBucketAcls] return acls; }
/** Example of listing the ACL entries for a blob. */ // [TARGET listAcls(BlobId)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "my_blob_name"] // [VARIABLE 42] public List<Acl> listBlobAcls(String bucketName, String blobName, long blobGeneration) { // [START listBlobAcls] BlobId blobId = BlobId.of(bucketName, blobName, blobGeneration); List<Acl> acls = storage.listAcls(blobId); for (Acl acl : acls) { // do something with ACL entry } // [END listBlobAcls] return acls; }
/** * Lists the ACL entries for this blob. * * <p>Example of listing the ACL entries. * * <pre>{@code * List<Acl> acls = blob.listAcls(); * for (Acl acl : acls) { * // do something with ACL entry * } * }</pre> * * @throws StorageException upon failure */ public List<Acl> listAcls() { return storage.listAcls(getBlobId()); }
/** * Lists the ACL entries for this bucket. * * <p>Example of listing the ACL entries. * * <pre>{@code * List<Acl> acls = bucket.listAcls(); * for (Acl acl : acls) { * // do something with ACL entry * } * }</pre> * * @throws StorageException upon failure */ public List<Acl> listAcls() { return storage.listAcls(getName()); }
@Test public void testListBucketAcl() { EasyMock.expect(storageRpcMock.listAcls(BUCKET_NAME1, new HashMap<StorageRpc.Option, Object>())) .andReturn(ImmutableList.of(ACL.toBucketPb(), OTHER_ACL.toBucketPb())); EasyMock.replay(storageRpcMock); initializeService(); List<Acl> acls = storage.listAcls(BUCKET_NAME1); assertEquals(ImmutableList.of(ACL, OTHER_ACL), acls); }
@Test public void testListAcls() throws Exception { initializeExpectedBucket(4); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.listAcls(BUCKET_INFO.getName())).andReturn(ACLS); replay(storage); initializeBucket(); assertEquals(ACLS, bucket.listAcls()); }
@Test public void testListBlobAcl() { BlobId blobId = BlobId.of(BUCKET_NAME1, BLOB_NAME1, 42L); EasyMock.expect(storageRpcMock.listAcls(BUCKET_NAME1, BLOB_NAME1, 42L)) .andReturn(ImmutableList.of(ACL.toObjectPb(), OTHER_ACL.toObjectPb())); EasyMock.replay(storageRpcMock); initializeService(); List<Acl> acls = storage.listAcls(blobId); assertEquals(ImmutableList.of(ACL, OTHER_ACL), acls); }
@Test public void testListAcls() throws Exception { initializeExpectedBlob(1); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.listAcls(BLOB_INFO.getBlobId())).andReturn(ACLS); replay(storage); initializeBlob(); assertEquals(ACLS, blob.listAcls()); }
Acl updatedAcl = storage.updateAcl(blobId, acl.toBuilder().setRole(Role.OWNER).build()); assertEquals(Role.OWNER, updatedAcl.getRole()); Set<Acl> acls = new HashSet<>(storage.listAcls(blobId)); assertTrue(acls.contains(updatedAcl)); assertTrue(storage.deleteAcl(blobId, User.ofAllAuthenticatedUsers())); storage.listAcls(otherBlobId); fail("Expected StorageException"); } catch (StorageException ex) {
private void testBucketAclRequesterPays(boolean requesterPays) { if (requesterPays) { 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(); Storage.BucketSourceOption[] bucketOptions = requesterPays ? new Storage.BucketSourceOption[] {Storage.BucketSourceOption.userProject(projectId)} : new Storage.BucketSourceOption[] {}; assertNull(storage.getAcl(BUCKET, User.ofAllAuthenticatedUsers(), bucketOptions)); assertFalse(storage.deleteAcl(BUCKET, User.ofAllAuthenticatedUsers(), bucketOptions)); Acl acl = Acl.of(User.ofAllAuthenticatedUsers(), Role.READER); assertNotNull(storage.createAcl(BUCKET, acl, bucketOptions)); Acl updatedAcl = storage.updateAcl(BUCKET, acl.toBuilder().setRole(Role.WRITER).build(), bucketOptions); assertEquals(Role.WRITER, updatedAcl.getRole()); Set<Acl> acls = new HashSet<>(); acls.addAll(storage.listAcls(BUCKET, bucketOptions)); assertTrue(acls.contains(updatedAcl)); assertTrue(storage.deleteAcl(BUCKET, User.ofAllAuthenticatedUsers(), bucketOptions)); assertNull(storage.getAcl(BUCKET, User.ofAllAuthenticatedUsers(), bucketOptions)); }
/** * Lists the ACL entries for this bucket. * * <p>Example of listing the ACL entries. * * <pre>{@code * List<Acl> acls = bucket.listAcls(); * for (Acl acl : acls) { * // do something with ACL entry * } * }</pre> * * @throws StorageException upon failure */ public List<Acl> listAcls() { return storage.listAcls(getName()); }
/** * Lists the ACL entries for this blob. * * <p>Example of listing the ACL entries. * * <pre>{@code * List<Acl> acls = blob.listAcls(); * for (Acl acl : acls) { * // do something with ACL entry * } * }</pre> * * @throws StorageException upon failure */ public List<Acl> listAcls() { return storage.listAcls(getBlobId()); }