use of com.google.cloud.storage.Acl.User in project google-cloud-java by GoogleCloudPlatform.
the class AclTest method testUserEntity.
@Test
public void testUserEntity() {
User acl = new User("u1");
assertEquals("u1", acl.getEmail());
assertEquals(Type.USER, acl.getType());
String pb = acl.toPb();
assertEquals(acl, Entity.fromPb(pb));
}
use of com.google.cloud.storage.Acl.User in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageSnippets method testBlobAcl.
@Test
public void testBlobAcl() {
String blobName = "test-blob-acl";
BlobId blobId = BlobId.of(BUCKET, "test-blob-acl");
BlobInfo blob = BlobInfo.newBuilder(blobId).build();
Blob createdBlob = storage.create(blob);
assertNull(storageSnippets.getBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
assertNotNull(storageSnippets.createBlobAcl(BUCKET, blobName, createdBlob.getGeneration()));
Acl updatedAcl = storageSnippets.updateBlobAcl(BUCKET, blobName, createdBlob.getGeneration());
assertEquals(Acl.Role.OWNER, updatedAcl.getRole());
Set<Acl> acls = Sets.newHashSet(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());
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
String nonExistingBlob = "test-blob-acl";
assertNull(storageSnippets.getBlobAcl(BUCKET, nonExistingBlob, 1L));
assertFalse(storageSnippets.deleteBlobAcl(BUCKET, nonExistingBlob, 1L));
try {
storageSnippets.createBlobAcl(BUCKET, nonExistingBlob, 1L);
fail("Expected StorageException");
} catch (StorageException ex) {
// expected
}
try {
storageSnippets.updateBlobAcl(BUCKET, nonExistingBlob, 1L);
fail("Expected StorageException");
} catch (StorageException ex) {
// expected
}
try {
storageSnippets.listBlobAcls(BUCKET, nonExistingBlob, 1L);
fail("Expected StorageException");
} catch (StorageException ex) {
// expected
}
}
use of com.google.cloud.storage.Acl.User in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method getBlobAcl.
/**
* 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;
}
use of com.google.cloud.storage.Acl.User in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageSnippets method testBucketAcl.
@Test
public void testBucketAcl() {
assertNull(storageSnippets.getBucketAcl(BUCKET));
assertFalse(storageSnippets.deleteBucketAcl(BUCKET));
assertNotNull(storageSnippets.createBucketAcl(BUCKET));
Acl updatedAcl = storageSnippets.updateBucketAcl(BUCKET);
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));
}
Aggregations