/** Example of updating a new ACL entry. */ // [TARGET updateAcl(Acl)] public Acl updateAcl() { // [START updateAcl] Acl acl = blob.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER)); // [END updateAcl] return acl; }
/** Example of creating a new ACL entry. */ // [TARGET createAcl(Acl)] public Acl createAcl() { // [START createAcl] Acl acl = bucket.createAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER)); // [END createAcl] return acl; }
/** Example of updating a new default ACL entry on a bucket. */ // [TARGET updateDefaultAcl(String, Acl)] // [VARIABLE "my_unique_bucket"] public Acl updateDefaultBucketAcl(String bucketName) { // [START updateDefaultBucketAcl] Acl acl = storage.updateDefaultAcl(bucketName, Acl.of(User.ofAllAuthenticatedUsers(), Role.OWNER)); // [END updateDefaultBucketAcl] return acl; }
/** 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; }
/** Example of updating a new ACL entry. */ // [TARGET updateAcl(Acl)] public Acl updateAcl() { // [START updateAcl] Acl acl = bucket.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER)); // [END updateAcl] return acl; }
/** Example of creating a new default ACL entry. */ // [TARGET createDefaultAcl(Acl)] public Acl createDefaultAcl() { // [START createDefaultAcl] Acl acl = bucket.createDefaultAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER)); // [END createDefaultAcl] return 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 default ACL entry. */ // [TARGET updateDefaultAcl(Acl)] public Acl updateDefaultAcl() { // [START updateDefaultAcl] Acl acl = bucket.updateDefaultAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER)); // [END updateDefaultAcl] return acl; }
/** Example of creating a new ACL entry on a bucket. */ // [TARGET createAcl(String, Acl)] // [VARIABLE "my_unique_bucket"] public Acl createBucketAcl(String bucketName) { // [START createBucketAcl] Acl acl = storage.createAcl(bucketName, Acl.of(User.ofAllAuthenticatedUsers(), Role.READER)); // [END createBucketAcl] return acl; }
/** Example of creating a new default ACL entry on a bucket. */ // [TARGET createDefaultAcl(String, Acl)] // [VARIABLE "my_unique_bucket"] public Acl createDefaultBucketAcl(String bucketName) { // [START createDefaultBucketAcl] Acl acl = storage.createDefaultAcl(bucketName, Acl.of(User.ofAllAuthenticatedUsers(), Role.READER)); // [END createDefaultBucketAcl] return acl; }
/** Example of updating a blob to be public-read. */ // [TARGET createAcl(BlobId, Acl)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "my_blob_name"] // [VARIABLE 42] public Acl blobToPublicRead(String bucketName, String blobName, long blobGeneration) { // [START storageMakePublic] BlobId blobId = BlobId.of(bucketName, blobName, blobGeneration); Acl acl = storage.createAcl(blobId, Acl.of(User.ofAllUsers(), Role.READER)); // [END storageMakePublic] return acl; }
/** Example of creating a new ACL entry on a blob. */ // [TARGET createAcl(BlobId, Acl)] // [VARIABLE "my_unique_bucket"] // [VARIABLE "my_blob_name"] // [VARIABLE 42] public Acl createBlobAcl(String bucketName, String blobName, long blobGeneration) { // [START createBlobAcl] BlobId blobId = BlobId.of(bucketName, blobName, blobGeneration); Acl acl = storage.createAcl(blobId, Acl.of(User.ofAllAuthenticatedUsers(), Role.READER)); // [END createBlobAcl] 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; }
@Override Tuple<BlobId, Acl> parse(String... args) { if (args.length >= 3) { BlobId blob; int nextArg; if (args.length == 3) { blob = BlobId.of(args[0], ""); nextArg = 1; } else if (args.length == 4) { blob = BlobId.of(args[0], args[1]); nextArg = 2; } else { throw new IllegalArgumentException("Too many arguments."); } String group = args[nextArg++]; Acl.Role role = Acl.Role.valueOf(args[nextArg]); return Tuple.of(blob, Acl.of(new Acl.Group(group), role)); } throw new IllegalArgumentException("Missing required bucket, groupEmail or role arguments."); }
@Override Tuple<BlobId, Acl> parse(String... args) { if (args.length >= 3) { BlobId blob; int nextArg; if (args.length == 3) { blob = BlobId.of(args[0], ""); nextArg = 1; } else if (args.length == 4) { blob = BlobId.of(args[0], args[1]); nextArg = 2; } else { throw new IllegalArgumentException("Too many arguments."); } String domain = args[nextArg++]; Acl.Role role = Acl.Role.valueOf(args[nextArg]); return Tuple.of(blob, Acl.of(new Acl.Domain(domain), role)); } throw new IllegalArgumentException("Missing required bucket, domain or role arguments."); }
@Override Tuple<BlobId, Acl> parse(String... args) { if (args.length >= 3) { BlobId blob; int nextArg; if (args.length == 3) { blob = BlobId.of(args[0], ""); nextArg = 1; } else if (args.length == 4) { blob = BlobId.of(args[0], args[1]); nextArg = 2; } else { throw new IllegalArgumentException("Too many arguments."); } String user = args[nextArg++]; Acl.Role role = Acl.Role.valueOf(args[nextArg]); return Tuple.of(blob, Acl.of(new Acl.User(user), role)); } throw new IllegalArgumentException("Missing required bucket, userEmail or role arguments."); }
@Test public void testWithAcl() throws IOException { Path path = Paths.get(URI.create("gs://bucket/path")); Acl acl = Acl.of(new Acl.User("king@example.com"), Acl.Role.OWNER); Files.write(path, "(✿◕ ‿◕ )ノ".getBytes(UTF_8), CloudStorageOptions.withAcl(acl)); assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).acl().get()) .contains(acl); }
@Test public void testAcl() throws IOException { Acl acl = Acl.of(new Acl.User("serf@example.com"), Acl.Role.READER); Files.write(path, HAPPY, CloudStorageOptions.withAcl(acl)); assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).acl().get()) .contains(acl); }
@Test public void testBucketDefaultAcl() { assertNull(storage.getDefaultAcl(BUCKET, User.ofAllAuthenticatedUsers())); assertFalse(storage.deleteDefaultAcl(BUCKET, User.ofAllAuthenticatedUsers())); Acl acl = Acl.of(User.ofAllAuthenticatedUsers(), Role.READER); assertNotNull(storage.createDefaultAcl(BUCKET, acl)); Acl updatedAcl = storage.updateDefaultAcl(BUCKET, acl.toBuilder().setRole(Role.OWNER).build()); assertEquals(Role.OWNER, updatedAcl.getRole()); Set<Acl> acls = new HashSet<>(); acls.addAll(storage.listDefaultAcls(BUCKET)); assertTrue(acls.contains(updatedAcl)); assertTrue(storage.deleteDefaultAcl(BUCKET, User.ofAllAuthenticatedUsers())); assertNull(storage.getDefaultAcl(BUCKET, User.ofAllAuthenticatedUsers())); }
@Test public void testOf() { Acl acl = Acl.of(User.ofAllUsers(), Role.READER); assertEquals(User.ofAllUsers(), acl.getEntity()); assertEquals(Role.READER, acl.getRole()); ObjectAccessControl objectPb = acl.toObjectPb(); assertEquals(acl, Acl.fromPb(objectPb)); BucketAccessControl bucketPb = acl.toBucketPb(); assertEquals(acl, Acl.fromPb(bucketPb)); } }