Skip to content

Commit 3291e67

Browse files
jerjougarrettjonesgoogle
authored andcommitted
---
yaml --- r: 5249 b: refs/heads/master c: 7729401 h: refs/heads/master i: 5247: 4aac721
1 parent 57d1a23 commit 3291e67

4 files changed

Lines changed: 63 additions & 1 deletion

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ddd25d6d57073c8cc205c749e10e88e6c5b9ed39
2+
refs/heads/master: 7729401e875c5296a6ba520912ca8c23332e08ab
33
refs/heads/travis: dae77e558b884bc1b165155482d76c8e40b0fca4
44
refs/heads/gh-pages: 229631582f8957646f81e92ae5a326504f48ee5b
55
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

trunk/google-cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,19 @@ public Acl getBucketAcl(String bucketName) {
717717
return acl;
718718
}
719719

720+
/**
721+
* Example of getting the ACL entry for a specific user on a bucket.
722+
*/
723+
// [TARGET getAcl(String, Entity)]
724+
// [VARIABLE "my_unique_bucket"]
725+
// [VARIABLE "google-cloud-java-tests@java-docs-samples-tests.iam.gserviceaccount.com"]
726+
public Acl getBucketAcl(String bucketName, String userEmail) {
727+
// [START storagePrintBucketAclForUser]
728+
Acl acl = storage.getAcl(bucketName, new User(userEmail));
729+
// [END storagePrintBucketAclForUser]
730+
return acl;
731+
}
732+
720733
/**
721734
* Example of deleting the ACL entry for an entity on a bucket.
722735
*/
@@ -858,6 +871,21 @@ public Acl getBlobAcl(String bucketName, String blobName, long blobGeneration) {
858871
return acl;
859872
}
860873

874+
/**
875+
* Example of getting the ACL entry for a specific user on a blob.
876+
*/
877+
// [TARGET getAcl(BlobId, Entity)]
878+
// [VARIABLE "my_unique_bucket"]
879+
// [VARIABLE "my_blob_name"]
880+
// [VARIABLE "google-cloud-java-tests@java-docs-samples-tests.iam.gserviceaccount.com"]
881+
public Acl getBlobAcl(String bucketName, String blobName, String userEmail) {
882+
// [START storagePrintFileAclForUser]
883+
BlobId blobId = BlobId.of(bucketName, blobName);
884+
Acl acl = storage.getAcl(blobId, new User(userEmail));
885+
// [END storagePrintFileAclForUser]
886+
return acl;
887+
}
888+
861889
/**
862890
* Example of deleting the ACL entry for an entity on a blob.
863891
*/

trunk/google-cloud-examples/src/test/java/com/google/cloud/examples/storage/snippets/ITStorageSnippets.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import com.google.cloud.Page;
2929
import com.google.cloud.storage.Acl;
30+
import com.google.cloud.storage.Acl.Role;
3031
import com.google.cloud.storage.Acl.User;
3132
import com.google.cloud.storage.Blob;
3233
import com.google.cloud.storage.BlobId;
@@ -63,6 +64,8 @@ public class ITStorageSnippets {
6364

6465
private static final Logger log = Logger.getLogger(ITStorageSnippets.class.getName());
6566
private static final String BUCKET = RemoteStorageHelper.generateBucketName();
67+
private static final String USER_EMAIL = "google-cloud-java-tests@"
68+
+ "java-docs-samples-tests.iam.gserviceaccount.com";
6669

6770
private static Storage storage;
6871
private static StorageSnippets storageSnippets;
@@ -290,6 +293,14 @@ public void testBucketAcl() {
290293
assertEquals(Acl.Role.OWNER, updatedAcl.getRole());
291294
Set<Acl> acls = Sets.newHashSet(storageSnippets.listBucketAcls(BUCKET));
292295
assertTrue(acls.contains(updatedAcl));
296+
297+
assertNotNull(storageSnippets.getBucketAcl(BUCKET));
298+
assertNull(storageSnippets.getBucketAcl(BUCKET, USER_EMAIL));
299+
storage.createAcl(BUCKET, Acl.of(new User(USER_EMAIL), Role.READER));
300+
Acl userAcl = storageSnippets.getBucketAcl(BUCKET, USER_EMAIL);
301+
assertNotNull(userAcl);
302+
assertEquals(USER_EMAIL, ((User)userAcl.getEntity()).getEmail());
303+
293304
assertTrue(storageSnippets.deleteBucketAcl(BUCKET));
294305
assertNull(storageSnippets.getBucketAcl(BUCKET));
295306
}
@@ -321,13 +332,20 @@ public void testBlobAcl() {
321332
storageSnippets.listBlobAcls(BUCKET, blobName, createdBlob.getGeneration()));
322333
assertTrue(acls.contains(updatedAcl));
323334

335+
assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, USER_EMAIL));
336+
storage.createAcl(BlobId.of(BUCKET, blobName), Acl.of(new User(USER_EMAIL), Role.READER));
337+
Acl userAcl = storageSnippets.getBlobAcl(BUCKET, blobName, USER_EMAIL);
338+
assertNotNull(userAcl);
339+
assertEquals(USER_EMAIL, ((User)userAcl.getEntity()).getEmail());
340+
324341
updatedAcl = storageSnippets.blobToPublicRead(BUCKET, blobName, createdBlob.getGeneration());
325342
assertEquals(Acl.Role.READER, updatedAcl.getRole());
326343
assertEquals(User.ofAllUsers(), updatedAcl.getEntity());
327344
acls = Sets.newHashSet(
328345
storageSnippets.listBlobAcls(BUCKET, blobName, createdBlob.getGeneration()));
329346
assertTrue(acls.contains(updatedAcl));
330347

348+
assertNotNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
331349
assertTrue(storageSnippets.deleteBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
332350
assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
333351
// test non-existing blob

trunk/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,13 @@ public static Builder newBuilder() {
22482248
* Acl acl = storage.getAcl(bucketName, User.ofAllAuthenticatedUsers());
22492249
* }</pre>
22502250
*
2251+
* <p>Example of getting the ACL entry for a specific user on a bucket.
2252+
* <pre> {@code
2253+
* String bucketName = "my_unique_bucket";
2254+
* String userEmail = "google-cloud-java-tests@java-docs-samples-tests.iam.gserviceaccount.com";
2255+
* Acl acl = storage.getAcl(bucketName, new User(userEmail));
2256+
* }</pre>
2257+
*
22512258
* @throws StorageException upon failure
22522259
*/
22532260
Acl getAcl(String bucket, Entity entity);
@@ -2418,6 +2425,15 @@ public static Builder newBuilder() {
24182425
* Acl acl = storage.getAcl(blobId, User.ofAllAuthenticatedUsers());
24192426
* }</pre>
24202427
*
2428+
* <p>Example of getting the ACL entry for a specific user on a blob.
2429+
* <pre> {@code
2430+
* String bucketName = "my_unique_bucket";
2431+
* String blobName = "my_blob_name";
2432+
* String userEmail = "google-cloud-java-tests@java-docs-samples-tests.iam.gserviceaccount.com";
2433+
* BlobId blobId = BlobId.of(bucketName, blobName);
2434+
* Acl acl = storage.getAcl(blobId, new User(userEmail));
2435+
* }</pre>
2436+
*
24212437
* @throws StorageException upon failure
24222438
*/
24232439
Acl getAcl(BlobId blob, Entity entity);

0 commit comments

Comments
 (0)