Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,19 @@ public Acl getBucketAcl(String bucketName) {
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]

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Acl acl = storage.getAcl(bucketName, new User(userEmail));
// [END storagePrintBucketAclForUser]
return acl;
}

/**
* Example of deleting the ACL entry for an entity on a bucket.
*/
Expand Down Expand Up @@ -858,6 +871,21 @@ public Acl getBlobAcl(String bucketName, String blobName, long blobGeneration) {
return acl;
}

/**
* 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 deleting the ACL entry for an entity on a blob.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.google.cloud.Page;
import com.google.cloud.storage.Acl;
import com.google.cloud.storage.Acl.Role;
import com.google.cloud.storage.Acl.User;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class ITStorageSnippets {

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

private static Storage storage;
private static StorageSnippets storageSnippets;
Expand Down Expand Up @@ -290,6 +293,14 @@ public void testBucketAcl() {
assertEquals(Acl.Role.OWNER, updatedAcl.getRole());
Set<Acl> acls = Sets.newHashSet(storageSnippets.listBucketAcls(BUCKET));
assertTrue(acls.contains(updatedAcl));

assertNotNull(storageSnippets.getBucketAcl(BUCKET));
assertNull(storageSnippets.getBucketAcl(BUCKET, USER_EMAIL));
storage.createAcl(BUCKET, Acl.of(new User(USER_EMAIL), Role.READER));
Acl userAcl = storageSnippets.getBucketAcl(BUCKET, USER_EMAIL);
assertNotNull(userAcl);
assertEquals(USER_EMAIL, ((User)userAcl.getEntity()).getEmail());

assertTrue(storageSnippets.deleteBucketAcl(BUCKET));
assertNull(storageSnippets.getBucketAcl(BUCKET));
}
Expand Down Expand Up @@ -321,13 +332,20 @@ public void testBlobAcl() {
storageSnippets.listBlobAcls(BUCKET, blobName, createdBlob.getGeneration()));
assertTrue(acls.contains(updatedAcl));

assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, USER_EMAIL));
storage.createAcl(BlobId.of(BUCKET, blobName), Acl.of(new User(USER_EMAIL), Role.READER));
Acl userAcl = storageSnippets.getBlobAcl(BUCKET, blobName, USER_EMAIL);
assertNotNull(userAcl);
assertEquals(USER_EMAIL, ((User)userAcl.getEntity()).getEmail());

updatedAcl = storageSnippets.blobToPublicRead(BUCKET, blobName, createdBlob.getGeneration());
assertEquals(Acl.Role.READER, updatedAcl.getRole());
assertEquals(User.ofAllUsers(), updatedAcl.getEntity());
acls = Sets.newHashSet(
storageSnippets.listBlobAcls(BUCKET, blobName, createdBlob.getGeneration()));
assertTrue(acls.contains(updatedAcl));

assertNotNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
assertTrue(storageSnippets.deleteBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
// test non-existing blob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,13 @@ public static Builder newBuilder() {
* Acl acl = storage.getAcl(bucketName, User.ofAllAuthenticatedUsers());
* }</pre>
*
* <p>Example of getting the ACL entry for a specific user on a bucket.
* <pre> {@code
* String bucketName = "my_unique_bucket";
* String userEmail = "google-cloud-java-tests@java-docs-samples-tests.iam.gserviceaccount.com";
* Acl acl = storage.getAcl(bucketName, new User(userEmail));
* }</pre>
*
* @throws StorageException upon failure
*/
Acl getAcl(String bucket, Entity entity);
Expand Down Expand Up @@ -2418,6 +2425,15 @@ public static Builder newBuilder() {
* Acl acl = storage.getAcl(blobId, User.ofAllAuthenticatedUsers());
* }</pre>
*
* <p>Example of getting the ACL entry for a specific user on a blob.
* <pre> {@code
* String bucketName = "my_unique_bucket";
* String blobName = "my_blob_name";
* String userEmail = "google-cloud-java-tests@java-docs-samples-tests.iam.gserviceaccount.com";
* BlobId blobId = BlobId.of(bucketName, blobName);
* Acl acl = storage.getAcl(blobId, new User(userEmail));
* }</pre>
*
* @throws StorageException upon failure
*/
Acl getAcl(BlobId blob, Entity entity);
Expand Down