/** * Updates an ACL entry on this blob. * * <p>Example of updating a new ACL entry. * * <pre>{@code * Acl acl = blob.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER)); * }</pre> * * @throws StorageException upon failure */ public Acl updateAcl(Acl acl) { return storage.updateAcl(getBlobId(), acl); }
/** * Updates an ACL entry on this bucket. * * <p>Example of updating a new ACL entry. * * <pre>{@code * Acl acl = bucket.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER)); * }</pre> * * @throws StorageException upon failure */ public Acl updateAcl(Acl acl) { return storage.updateAcl(getName(), acl); }
/** Example of updating a new ACL entry on a bucket. */ // [TARGET updateAcl(String, Acl)] // [VARIABLE "my_unique_bucket"] public Acl updateBucketAcl(String bucketName) { // [START updateBucketAcl] Acl acl = storage.updateAcl(bucketName, Acl.of(User.ofAllAuthenticatedUsers(), Role.OWNER)); // [END updateBucketAcl] return acl; }
/** Example of updating a new ACL entry on a blob. */ // [TARGET updateAcl(BlobId, Acl)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "my_blob_name"] // [VARIABLE 42] public Acl updateBlobAcl(String bucketName, String blobName, long blobGeneration) { // [START updateBlobAcl] BlobId blobId = BlobId.of(bucketName, blobName, blobGeneration); Acl acl = storage.updateAcl(blobId, Acl.of(User.ofAllAuthenticatedUsers(), Role.OWNER)); // [END updateBlobAcl] return acl; }
@Test public void testUpdateAcl() throws Exception { initializeExpectedBlob(1); expect(storage.getOptions()).andReturn(mockOptions); Acl returnedAcl = ACL.toBuilder().setEtag("ETAG").setId("ID").build(); expect(storage.updateAcl(BLOB_INFO.getBlobId(), ACL)).andReturn(returnedAcl); replay(storage); initializeBlob(); assertEquals(returnedAcl, blob.updateAcl(ACL)); }
@Test public void testUpdateAcl() throws Exception { initializeExpectedBucket(4); expect(storage.getOptions()).andReturn(mockOptions); Acl returnedAcl = ACL.toBuilder().setEtag("ETAG").setId("ID").build(); expect(storage.updateAcl(BUCKET_INFO.getName(), ACL)).andReturn(returnedAcl); replay(storage); initializeBucket(); assertEquals(returnedAcl, bucket.updateAcl(ACL)); }
@Test public void testUpdateBucketAcl() { Acl returnedAcl = ACL.toBuilder().setEtag("ETAG").setId("ID").build(); EasyMock.expect( storageRpcMock.patchAcl( ACL.toBucketPb().setBucket(BUCKET_NAME1), new HashMap<StorageRpc.Option, Object>())) .andReturn(returnedAcl.toBucketPb()); EasyMock.replay(storageRpcMock); initializeService(); Acl acl = storage.updateAcl(BUCKET_NAME1, ACL); assertEquals(returnedAcl, acl); }
@Test public void testUpdateBlobAcl() { BlobId blobId = BlobId.of(BUCKET_NAME1, BLOB_NAME1, 42L); Acl returnedAcl = ACL.toBuilder().setEtag("ETAG").setId("ID").build(); EasyMock.expect( storageRpcMock.patchAcl( ACL.toObjectPb().setBucket(BUCKET_NAME1).setObject(BLOB_NAME1).setGeneration(42L))) .andReturn(returnedAcl.toObjectPb()); EasyMock.replay(storageRpcMock); initializeService(); Acl acl = storage.updateAcl(blobId, ACL); assertEquals(returnedAcl, acl); }
Acl acl = Acl.of(User.ofAllAuthenticatedUsers(), Role.READER); assertNotNull(storage.createAcl(blobId, acl)); Acl updatedAcl = storage.updateAcl(blobId, acl.toBuilder().setRole(Role.OWNER).build()); assertEquals(Role.OWNER, updatedAcl.getRole()); Set<Acl> acls = new HashSet<>(storage.listAcls(blobId)); storage.updateAcl(otherBlobId, acl); 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)); }
/** * Updates an ACL entry on this bucket. * * <p>Example of updating a new ACL entry. * * <pre>{@code * Acl acl = bucket.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER)); * }</pre> * * @throws StorageException upon failure */ public Acl updateAcl(Acl acl) { return storage.updateAcl(getName(), acl); }
/** * Updates an ACL entry on this blob. * * <p>Example of updating a new ACL entry. * * <pre>{@code * Acl acl = blob.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER)); * }</pre> * * @throws StorageException upon failure */ public Acl updateAcl(Acl acl) { return storage.updateAcl(getBlobId(), acl); }