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 @@ -448,17 +448,17 @@ private static boolean processedAsFolder(StorageObject so, String delimiter, Str
}

@Override
public Policy getPolicy(String bucket) {
public Policy getIamPolicy(String bucket) {
throw new UnsupportedOperationException();
}

@Override
public Policy updatePolicy(String bucket, Policy policy) {
public Policy setIamPolicy(String bucket, Policy policy) {
throw new UnsupportedOperationException();
}

@Override
public TestIamPermissionsResponse testPermissions(String bucket, List<String> permissions) {
public TestIamPermissionsResponse testIamPermissions(String bucket, List<String> permissions) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2378,13 +2378,13 @@ public static Builder newBuilder() {
* <p>Example of getting the IAM policy for a bucket.
* <pre> {@code
* String bucketName = "my_unique_bucket";
* Policy policy = storage.getPolicy(bucketName);
* Policy policy = storage.getIamPolicy(bucketName);
* }</pre>
*
* @throws StorageException upon failure
*/
@GcpLaunchStage.Alpha
Policy getPolicy(String bucket);
Policy getIamPolicy(String bucket);

/**
* Updates the IAM policy on the specified bucket.
Expand All @@ -2393,9 +2393,9 @@ public static Builder newBuilder() {
* <pre>{@code
* // We want to make all objects in our bucket publicly readable.
* String bucketName = "my_unique_bucket";
* Policy currentPolicy = storage.getPolicy(bucketName);
* Policy currentPolicy = storage.getIamPolicy(bucketName);
* Policy updatedPolicy =
* storage.updatePolicy(
* storage.setIamPolicy(
* bucketName,
* currentPolicy.toBuilder()
* .addIdentity(StorageRoles.objectViewer(), Identity.allUsers())
Expand All @@ -2405,7 +2405,7 @@ public static Builder newBuilder() {
* @throws StorageException upon failure
*/
@GcpLaunchStage.Alpha
Policy updatePolicy(String bucket, Policy policy);
Policy setIamPolicy(String bucket, Policy policy);

/**
* Tests whether the caller holds the permissions on the specified bucket. Returns a list of
Expand All @@ -2415,7 +2415,7 @@ public static Builder newBuilder() {
* <pre> {@code
* String bucketName = "my_unique_bucket";
* List<Boolean> response =
* storage.testPermissions(
* storage.testIamPermissions(
* bucket,
* ImmutableList.of("storage.buckets.get", "storage.buckets.getIamPolicy"));
* for (boolean hasPermission : response) {
Expand All @@ -2426,5 +2426,5 @@ public static Builder newBuilder() {
* @throws StorageException upon failure
*/
@GcpLaunchStage.Alpha
List<Boolean> testPermissions(String bucket, List<String> permissions);
List<Boolean> testIamPermissions(String bucket, List<String> permissions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -862,12 +862,12 @@ public List<ObjectAccessControl> call() {
}

@Override
public Policy getPolicy(final String bucket) {
public Policy getIamPolicy(final String bucket) {
try {
return convertFromApiPolicy(runWithRetries(new Callable<com.google.api.services.storage.model.Policy>() {
@Override
public com.google.api.services.storage.model.Policy call() {
return storageRpc.getPolicy(bucket);
return storageRpc.getIamPolicy(bucket);
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()));
} catch (RetryHelperException e){
Expand All @@ -876,12 +876,12 @@ public com.google.api.services.storage.model.Policy call() {
}

@Override
public Policy updatePolicy(final String bucket, final Policy policy) {
public Policy setIamPolicy(final String bucket, final Policy policy) {
try {
return convertFromApiPolicy(runWithRetries(new Callable<com.google.api.services.storage.model.Policy>() {
@Override
public com.google.api.services.storage.model.Policy call() {
return storageRpc.updatePolicy(bucket, convertToApiPolicy(policy));
return storageRpc.setIamPolicy(bucket, convertToApiPolicy(policy));
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()));
} catch (RetryHelperException e) {
Expand All @@ -890,12 +890,12 @@ public com.google.api.services.storage.model.Policy call() {
}

@Override
public List<Boolean> testPermissions(final String bucket, final List<String> permissions) {
public List<Boolean> testIamPermissions(final String bucket, final List<String> permissions) {
try {
TestIamPermissionsResponse response = runWithRetries(new Callable<TestIamPermissionsResponse>() {
@Override
public TestIamPermissionsResponse call() {
return storageRpc.testPermissions(bucket, permissions);
return storageRpc.testIamPermissions(bucket, permissions);
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock());
final Set<String> heldPermissions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ public List<ObjectAccessControl> listAcls(String bucket, String object, Long gen
}

@Override
public Policy getPolicy(String bucket) {
public Policy getIamPolicy(String bucket) {
try {
return storage.buckets().getIamPolicy(bucket).execute();
} catch (IOException ex) {
Expand All @@ -847,7 +847,7 @@ public Policy getPolicy(String bucket) {
}

@Override
public Policy updatePolicy(String bucket, Policy policy) {
public Policy setIamPolicy(String bucket, Policy policy) {
try {
return storage.buckets().setIamPolicy(bucket, policy).execute();
} catch (IOException ex) {
Expand All @@ -856,7 +856,7 @@ public Policy updatePolicy(String bucket, Policy policy) {
}

@Override
public TestIamPermissionsResponse testPermissions(String bucket, List<String> permissions) {
public TestIamPermissionsResponse testIamPermissions(String bucket, List<String> permissions) {
try {
return storage.buckets().testIamPermissions(bucket, permissions).execute();
} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,19 +435,19 @@ void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset,
*
* @throws StorageException upon failure
*/
Policy getPolicy(String bucket);
Policy getIamPolicy(String bucket);

/**
* Updates the IAM policy for the specified bucket.
*
* @throws StorageException upon failure
*/
Policy updatePolicy(String bucket, Policy policy);
Policy setIamPolicy(String bucket, Policy policy);

/**
* Tests whether the caller holds the specified permissions for the specified bucket.
*
* @throws StorageException upon failure
*/
TestIamPermissionsResponse testPermissions(String bucket, List<String> permissions);
TestIamPermissionsResponse testIamPermissions(String bucket, List<String> permissions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1983,15 +1983,15 @@ public void testListBlobAcl() {
}

@Test
public void testGetPolicy() {
EasyMock.expect(storageRpcMock.getPolicy(BUCKET_NAME1)).andReturn(API_POLICY1);
public void testGetIamPolicy() {
EasyMock.expect(storageRpcMock.getIamPolicy(BUCKET_NAME1)).andReturn(API_POLICY1);
EasyMock.replay(storageRpcMock);
initializeService();
assertEquals(LIB_POLICY1, storage.getPolicy(BUCKET_NAME1));
assertEquals(LIB_POLICY1, storage.getIamPolicy(BUCKET_NAME1));
}

@Test
public void testUpdatePolicy() {
public void testSetIamPolicy() {
com.google.api.services.storage.model.Policy preCommitApiPolicy =
new com.google.api.services.storage.model.Policy()
.setBindings(ImmutableList.of(
Expand Down Expand Up @@ -2036,18 +2036,18 @@ public void testUpdatePolicy() {
.setEtag(POLICY_ETAG2)
.build();

EasyMock.expect(storageRpcMock.getPolicy(BUCKET_NAME1)).andReturn(API_POLICY1);
EasyMock.expect(storageRpcMock.getIamPolicy(BUCKET_NAME1)).andReturn(API_POLICY1);
EasyMock.expect(
storageRpcMock.updatePolicy(
storageRpcMock.setIamPolicy(
eq(BUCKET_NAME1),
eqApiPolicy(preCommitApiPolicy)))
.andReturn(postCommitApiPolicy);
EasyMock.replay(storageRpcMock);
initializeService();

Policy currentPolicy = storage.getPolicy(BUCKET_NAME1);
Policy currentPolicy = storage.getIamPolicy(BUCKET_NAME1);
Policy updatedPolicy =
storage.updatePolicy(
storage.setIamPolicy(
BUCKET_NAME1,
currentPolicy.toBuilder()
.addIdentity(StorageRoles.admin(), Identity.group("test-group@gmail.com"))
Expand All @@ -2056,30 +2056,30 @@ public void testUpdatePolicy() {
}

@Test
public void testTestPermissionsNull() {
public void testTestIamPermissionsNull() {
ImmutableList<Boolean> expectedPermissions = ImmutableList.of(false, false, false);
ImmutableList<String> checkedPermissions =
ImmutableList.of("storage.buckets.get", "storage.buckets.getIamPolicy", "storage.objects.list");

EasyMock.expect(storageRpcMock.testPermissions(BUCKET_NAME1, checkedPermissions))
EasyMock.expect(storageRpcMock.testIamPermissions(BUCKET_NAME1, checkedPermissions))
.andReturn(new TestIamPermissionsResponse());
EasyMock.replay(storageRpcMock);
initializeService();
assertEquals(expectedPermissions, storage.testPermissions(BUCKET_NAME1, checkedPermissions));
assertEquals(expectedPermissions, storage.testIamPermissions(BUCKET_NAME1, checkedPermissions));
}

@Test
public void testTestPermissionsNonNull() {
public void testTestIamPermissionsNonNull() {
ImmutableList<Boolean> expectedPermissions = ImmutableList.of(true, false, true);
ImmutableList<String> checkedPermissions =
ImmutableList.of("storage.buckets.get", "storage.buckets.getIamPolicy", "storage.objects.list");

EasyMock.expect(storageRpcMock.testPermissions(BUCKET_NAME1, checkedPermissions))
EasyMock.expect(storageRpcMock.testIamPermissions(BUCKET_NAME1, checkedPermissions))
.andReturn(new TestIamPermissionsResponse()
.setPermissions(ImmutableList.of("storage.objects.list", "storage.buckets.get")));
EasyMock.replay(storageRpcMock);
initializeService();
assertEquals(expectedPermissions, storage.testPermissions(BUCKET_NAME1, checkedPermissions));
assertEquals(expectedPermissions, storage.testIamPermissions(BUCKET_NAME1, checkedPermissions));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1463,19 +1463,19 @@ public void testBucketPolicy() {
StorageRoles.legacyObjectReader(), newHashSet(Identity.allUsers()));

// Validate getting policy.
Policy currentPolicy = storage.getPolicy(BUCKET);
Policy currentPolicy = storage.getIamPolicy(BUCKET);
assertEquals(bindingsWithoutPublicRead, currentPolicy.getBindings());

// Validate updating policy.
Policy updatedPolicy =
storage.updatePolicy(
storage.setIamPolicy(
BUCKET,
currentPolicy.toBuilder()
.addIdentity(StorageRoles.legacyObjectReader(), Identity.allUsers())
.build());
assertEquals(bindingsWithPublicRead, updatedPolicy.getBindings());
Policy revertedPolicy =
storage.updatePolicy(
storage.setIamPolicy(
BUCKET,
updatedPolicy.toBuilder()
.removeIdentity(StorageRoles.legacyObjectReader(), Identity.allUsers())
Expand All @@ -1486,7 +1486,7 @@ public void testBucketPolicy() {
List<Boolean> expectedPermissions = ImmutableList.of(true, true);
assertEquals(
expectedPermissions,
storage.testPermissions(
storage.testIamPermissions(
BUCKET,
ImmutableList.of("storage.buckets.getIamPolicy", "storage.buckets.setIamPolicy")));
}
Expand Down