/** Example of creating a new ACL entry. */ // [TARGET createAcl(Acl)] public Acl createAcl() { // [START createAcl] Acl acl = blob.createAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER)); // [END createAcl] return acl; }
/** * Sets the ACL according to the provided {@code params}, using the {@code storage} service. If * {@code params.x()} returns a complete blob identity, the {@code params.y()} ACL is added to * the blob. If {@code params.x().name()} is empty, the {@code params.y()} ACL is added to the * bucket identified by {@code params.x().bucket()}. */ @Override public void run(Storage storage, Tuple<BlobId, Acl> params) { BlobId blobId = params.x(); Acl acl = params.y(); if (blobId.getName().isEmpty()) { Bucket bucket = storage.get(blobId.getBucket()); if (bucket == null) { System.out.printf("Bucket %s does not exist%n", blobId.getBucket()); return; } acl = bucket.createAcl(acl); System.out.printf("Added ACL %s to bucket %s%n", acl, blobId.getBucket()); } else { Blob blob = storage.get(blobId); if (blob == null) { System.out.printf("Blob %s does not exist%n", blobId); return; } acl = blob.createAcl(acl); System.out.printf("Added ACL %s to blob %s%n", acl, blobId); } } }
@Test public void testCreateAcl() throws Exception { initializeExpectedBlob(1); expect(storage.getOptions()).andReturn(mockOptions); Acl returnedAcl = ACL.toBuilder().setEtag("ETAG").setId("ID").build(); expect(storage.createAcl(BLOB_INFO.getBlobId(), ACL)).andReturn(returnedAcl); replay(storage); initializeBlob(); assertEquals(returnedAcl, blob.createAcl(ACL)); }