/** Example of getting the ACL entry for an entity on a bucket. */ // [TARGET getAcl(String, Entity)] // [VARIABLE "my_unique_bucket"] public Acl getBucketAcl(String bucketName) { // [START getBucketAcl] Acl acl = storage.getAcl(bucketName, User.ofAllAuthenticatedUsers()); // [END getBucketAcl] return acl; }
/** Example of getting the ACL entry for a specific user on a bucket. */ // [TARGET getAcl(String, Entity)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "google-cloud-java-tests@java-docs-samples-tests.iam.gserviceaccount.com"] public Acl getBucketAcl(String bucketName, String userEmail) { // [START storagePrintBucketAclForUser] Acl acl = storage.getAcl(bucketName, new User(userEmail)); // [END storagePrintBucketAclForUser] return acl; }
/** * Returns the ACL entry for the specified entity on this bucket or {@code null} if not found. * * <p>Example of getting the ACL entry for an entity. * * <pre>{@code * Acl acl = bucket.getAcl(User.ofAllAuthenticatedUsers()); * }</pre> * * @throws StorageException upon failure */ public Acl getAcl(Entity entity) { return storage.getAcl(getName(), entity); }
/** * Returns the ACL entry for the specified entity on this blob or {@code null} if not found. * * <p>Example of getting the ACL entry for an entity. * * <pre>{@code * Acl acl = blob.getAcl(User.ofAllAuthenticatedUsers()); * }</pre> * * @throws StorageException upon failure */ public Acl getAcl(Entity entity) { return storage.getAcl(getBlobId(), entity); }
/** Example of getting the ACL entry for a specific user on a blob. */ // [TARGET getAcl(BlobId, Entity)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "my_blob_name"] // [VARIABLE "google-cloud-java-tests@java-docs-samples-tests.iam.gserviceaccount.com"] public Acl getBlobAcl(String bucketName, String blobName, String userEmail) { // [START storagePrintFileAclForUser] BlobId blobId = BlobId.of(bucketName, blobName); Acl acl = storage.getAcl(blobId, new User(userEmail)); // [END storagePrintFileAclForUser] return acl; }
/** Example of getting the ACL entry for an entity on a blob. */ // [TARGET getAcl(BlobId, Entity)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "my_blob_name"] // [VARIABLE 42] public Acl getBlobAcl(String bucketName, String blobName, long blobGeneration) { // [START getBlobAcl] BlobId blobId = BlobId.of(bucketName, blobName, blobGeneration); Acl acl = storage.getAcl(blobId, User.ofAllAuthenticatedUsers()); // [END getBlobAcl] return acl; }
@Test public void testGetBucketAclNull() { EasyMock.expect( storageRpcMock.getAcl( BUCKET_NAME1, "allAuthenticatedUsers", new HashMap<StorageRpc.Option, Object>())) .andReturn(null); EasyMock.replay(storageRpcMock); initializeService(); assertNull(storage.getAcl(BUCKET_NAME1, User.ofAllAuthenticatedUsers())); }
@Test public void testGetBucketAcl() { EasyMock.expect( storageRpcMock.getAcl( BUCKET_NAME1, "allAuthenticatedUsers", new HashMap<StorageRpc.Option, Object>())) .andReturn(ACL.toBucketPb()); EasyMock.replay(storageRpcMock); initializeService(); Acl acl = storage.getAcl(BUCKET_NAME1, User.ofAllAuthenticatedUsers()); assertEquals(ACL, acl); }
@Test public void testGetBlobAclNull() { BlobId blobId = BlobId.of(BUCKET_NAME1, BLOB_NAME1, 42L); EasyMock.expect(storageRpcMock.getAcl(BUCKET_NAME1, BLOB_NAME1, 42L, "allAuthenticatedUsers")) .andReturn(null); EasyMock.replay(storageRpcMock); initializeService(); assertNull(storage.getAcl(blobId, User.ofAllAuthenticatedUsers())); }
@Test public void testGetAcl() throws Exception { initializeExpectedBucket(4); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.getAcl(BUCKET_INFO.getName(), User.ofAllAuthenticatedUsers())).andReturn(ACL); replay(storage); initializeBucket(); assertEquals(ACL, bucket.getAcl(User.ofAllAuthenticatedUsers())); }
@Test public void testGetAcl() throws Exception { initializeExpectedBlob(1); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.getAcl(BLOB_INFO.getBlobId(), User.ofAllAuthenticatedUsers())).andReturn(ACL); replay(storage); initializeBlob(); assertEquals(ACL, blob.getAcl(User.ofAllAuthenticatedUsers())); }
@Test public void testGetBlobAcl() { BlobId blobId = BlobId.of(BUCKET_NAME1, BLOB_NAME1, 42L); EasyMock.expect(storageRpcMock.getAcl(BUCKET_NAME1, BLOB_NAME1, 42L, "allAuthenticatedUsers")) .andReturn(ACL.toObjectPb()); EasyMock.replay(storageRpcMock); initializeService(); Acl acl = storage.getAcl(blobId, User.ofAllAuthenticatedUsers()); assertEquals(ACL, acl); }
BlobInfo blob = BlobInfo.newBuilder(blobId).build(); storage.create(blob); assertNull(storage.getAcl(blobId, User.ofAllAuthenticatedUsers())); Acl acl = Acl.of(User.ofAllAuthenticatedUsers(), Role.READER); assertNotNull(storage.createAcl(blobId, acl)); assertTrue(acls.contains(updatedAcl)); assertTrue(storage.deleteAcl(blobId, User.ofAllAuthenticatedUsers())); assertNull(storage.getAcl(blobId, User.ofAllAuthenticatedUsers())); assertNull(storage.getAcl(otherBlobId, User.ofAllAuthenticatedUsers())); fail("Expected an 'Invalid argument' exception"); } catch (StorageException e) {
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)); }
/** * Returns the ACL entry for the specified entity on this bucket or {@code null} if not found. * * <p>Example of getting the ACL entry for an entity. * * <pre>{@code * Acl acl = bucket.getAcl(User.ofAllAuthenticatedUsers()); * }</pre> * * @throws StorageException upon failure */ public Acl getAcl(Entity entity) { return storage.getAcl(getName(), entity); }
/** * Returns the ACL entry for the specified entity on this blob or {@code null} if not found. * * <p>Example of getting the ACL entry for an entity. * * <pre>{@code * Acl acl = blob.getAcl(User.ofAllAuthenticatedUsers()); * }</pre> * * @throws StorageException upon failure */ public Acl getAcl(Entity entity) { return storage.getAcl(getBlobId(), entity); }