/** * Updates an ACL entry on this bucket. * * <p>Example of updating a new ACL entry. * * <pre>{@code * Acl acl = bucket.updateAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER)); * }</pre> * * @throws StorageException upon failure */ public Acl updateAcl(Acl acl) { return storage.updateAcl(getName(), acl); }
/** * Returns the ACL entry for the specified entity on this bucket or {@code null} if not found. * * <p>Example of getting the ACL entry for an entity. * * <pre>{@code * Acl acl = bucket.getAcl(User.ofAllAuthenticatedUsers()); * }</pre> * * @throws StorageException upon failure */ public Acl getAcl(Entity entity) { return storage.getAcl(getName(), entity); }
/** * Creates a new ACL entry on this bucket. * * <p>Example of creating a new ACL entry. * * <pre>{@code * Acl acl = bucket.createAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER)); * }</pre> * * @throws StorageException upon failure */ public Acl createAcl(Acl acl) { return storage.createAcl(getName(), acl); }
/** * Updates a default blob ACL entry on this bucket. * * <p>Default ACLs are applied to a new blob within the bucket when no ACL was provided for that * blob. * * <p>Example of updating a new default ACL entry. * * <pre>{@code * Acl acl = bucket.updateDefaultAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.OWNER)); * }</pre> * * @throws StorageException upon failure */ public Acl updateDefaultAcl(Acl acl) { return storage.updateDefaultAcl(getName(), acl); }
/** * Creates a new default blob ACL entry on this bucket. * * <p>Default ACLs are applied to a new blob within the bucket when no ACL was provided for that * blob. * * <p>Example of creating a new default ACL entry. * * <pre>{@code * Acl acl = bucket.createDefaultAcl(Acl.of(User.ofAllAuthenticatedUsers(), Acl.Role.READER)); * }</pre> * * @throws StorageException upon failure */ public Acl createDefaultAcl(Acl acl) { return storage.createDefaultAcl(getName(), acl); }
/** * Lists the ACL entries for this bucket. * * <p>Example of listing the ACL entries. * * <pre>{@code * List<Acl> acls = bucket.listAcls(); * for (Acl acl : acls) { * // do something with ACL entry * } * }</pre> * * @throws StorageException upon failure */ public List<Acl> listAcls() { return storage.listAcls(getName()); }
/** * Returns the default object ACL entry for the specified entity on this bucket or {@code null} if * not found. * * <p>Default ACLs are applied to a new blob within the bucket when no ACL was provided for that * blob. * * <p>Example of getting the default ACL entry for an entity. * * <pre>{@code * Acl acl = bucket.getDefaultAcl(User.ofAllAuthenticatedUsers()); * }</pre> * * @throws StorageException upon failure */ public Acl getDefaultAcl(Entity entity) { return storage.getDefaultAcl(getName(), entity); }
/** * Returns the paginated list of {@code Blob} in this bucket. * * <p>Example of listing the blobs in the bucket. * * <pre>{@code * Page<Blob> blobs = bucket.list(); * Iterator<Blob> blobIterator = blobs.iterateAll(); * while (blobIterator.hasNext()) { * Blob blob = blobIterator.next(); * // do something with the blob * } * }</pre> * * @param options options for listing blobs * @throws StorageException upon failure */ public Page<Blob> list(BlobListOption... options) { return storage.list(getName(), options); }
/** * Lists the default blob ACL entries for this bucket. * * <p>Default ACLs are applied to a new blob within the bucket when no ACL was provided for that * blob. * * <p>Example of listing the default ACL entries. * * <pre>{@code * List<Acl> acls = bucket.listDefaultAcls(); * for (Acl acl : acls) { * // do something with ACL entry * } * }</pre> * * @throws StorageException upon failure */ public List<Acl> listDefaultAcls() { return storage.listDefaultAcls(getName()); }
/** * Deletes the ACL entry for the specified entity on this bucket. * * <p>Example of deleting the ACL entry for an entity. * * <pre>{@code * boolean deleted = bucket.deleteAcl(User.ofAllAuthenticatedUsers()); * if (deleted) { * // the acl entry was deleted * } else { * // the acl entry was not found * } * }</pre> * * @return {@code true} if the ACL was deleted, {@code false} if it was not found * @throws StorageException upon failure */ public boolean deleteAcl(Entity entity) { return storage.deleteAcl(getName(), entity); }
/** * Returns the requested blob in this bucket or {@code null} if not found. * * <p>Example of getting a blob in the bucket, only if its metageneration matches a value, * otherwise a {@link StorageException} is thrown. * * <pre>{@code * String blobName = "my_blob_name"; * long generation = 42; * Blob blob = bucket.get(blobName, BlobGetOption.generationMatch(generation)); * }</pre> * * @param blob name of the requested blob * @param options blob search options * @throws StorageException upon failure */ public Blob get(String blob, BlobGetOption... options) { return storage.get(BlobId.of(getName(), blob), options); }
/** * Fetches current bucket's latest information. Returns {@code null} if the bucket does not exist. * * <p>Example of getting the bucket's latest information, if its generation does not match the * {@link Bucket#getMetageneration()} value, otherwise a {@link StorageException} is thrown. * * <pre>{@code * Bucket latestBucket = bucket.reload(BucketSourceOption.metagenerationMatch()); * if (latestBucket == null) { * // the bucket was not found * } * }</pre> * * @param options bucket read options * @return a {@code Bucket} object with latest information or {@code null} if not found * @throws StorageException upon failure */ public Bucket reload(BucketSourceOption... options) { return storage.get(getName(), toGetOptions(this, options)); }
/** * Deletes this bucket. * * <p>Example of deleting the bucket, if its metageneration matches the {@link * Bucket#getMetageneration()} value, otherwise a {@link StorageException} is thrown. * * <pre>{@code * boolean deleted = bucket.delete(BucketSourceOption.metagenerationMatch()); * if (deleted) { * // the bucket was deleted * } else { * // the bucket was not found * } * }</pre> * * @param options bucket delete options * @return {@code true} if bucket was deleted, {@code false} if it was not found * @throws StorageException upon failure */ public boolean delete(BucketSourceOption... options) { return storage.delete(getName(), toSourceOptions(this, options)); }
@Test public void testListBuckets() throws IOException { boolean bucketFound = false; boolean rpBucketFound = false; for (Bucket b : CloudStorageFileSystem.listBuckets(project).iterateAll()) { bucketFound |= BUCKET.equals(b.getName()); rpBucketFound |= REQUESTER_PAYS_BUCKET.equals(b.getName()); } assertWithMessage("listBucket should have found the test bucket").that(bucketFound).isTrue(); assertWithMessage("listBucket should have found the test requester-pays bucket") .that(rpBucketFound) .isTrue(); }
@Test public void testGet() throws Exception { initializeExpectedBucket(5); Blob expectedBlob = new Blob( serviceMockReturnsOptions, new BlobInfo.BuilderImpl(BlobInfo.newBuilder("b", "n").build())); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.get(BlobId.of(expectedBucket.getName(), "n"), new Storage.BlobGetOption[0])) .andReturn(expectedBlob); replay(storage); initializeBucket(); Blob blob = bucket.get("n"); assertEquals(expectedBlob, blob); }
@Test public void testGetBucketWithSelectedFields() { Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance(); EasyMock.expect( storageRpcMock.get( EasyMock.eq(BucketInfo.of(BUCKET_NAME1).toPb()), EasyMock.capture(capturedOptions))) .andReturn(BUCKET_INFO1.toPb()); EasyMock.replay(storageRpcMock); initializeService(); Bucket bucket = storage.get(BUCKET_NAME1, BUCKET_GET_METAGENERATION, BUCKET_GET_FIELDS); assertEquals( BUCKET_GET_METAGENERATION.getValue(), capturedOptions.getValue().get(BUCKET_GET_METAGENERATION.getRpcOption())); String selector = (String) capturedOptions.getValue().get(BLOB_GET_FIELDS.getRpcOption()); assertTrue(selector.contains("name")); assertTrue(selector.contains("location")); assertTrue(selector.contains("acl")); assertEquals(17, selector.length()); assertEquals(BUCKET_INFO1.getName(), bucket.getName()); }
@Test public void testGetBucketWithEmptyFields() { Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance(); EasyMock.expect( storageRpcMock.get( EasyMock.eq(BucketInfo.of(BUCKET_NAME1).toPb()), EasyMock.capture(capturedOptions))) .andReturn(BUCKET_INFO1.toPb()); EasyMock.replay(storageRpcMock); initializeService(); Bucket bucket = storage.get(BUCKET_NAME1, BUCKET_GET_METAGENERATION, BUCKET_GET_EMPTY_FIELDS); assertEquals( BUCKET_GET_METAGENERATION.getValue(), capturedOptions.getValue().get(BUCKET_GET_METAGENERATION.getRpcOption())); String selector = (String) capturedOptions.getValue().get(BLOB_GET_FIELDS.getRpcOption()); assertTrue(selector.contains("name")); assertEquals(4, selector.length()); assertEquals(BUCKET_INFO1.getName(), bucket.getName()); }
@Test public void testGetBucketSelectedFields() { Bucket remoteBucket = storage.get(BUCKET, Storage.BucketGetOption.fields(BucketField.ID)); assertEquals(BUCKET, remoteBucket.getName()); assertNull(remoteBucket.getCreateTime()); assertNotNull(remoteBucket.getGeneratedId()); }
@Test public void testGetBucketEmptyFields() { Bucket remoteBucket = storage.get(BUCKET, Storage.BucketGetOption.fields()); assertEquals(BUCKET, remoteBucket.getName()); assertNull(remoteBucket.getCreateTime()); assertNull(remoteBucket.getSelfLink()); }
@Test public void testGetBucketAllSelectedFields() { Bucket remoteBucket = storage.get(BUCKET, Storage.BucketGetOption.fields(BucketField.values())); assertEquals(BUCKET, remoteBucket.getName()); assertNotNull(remoteBucket.getCreateTime()); assertNotNull(remoteBucket.getSelfLink()); }