Skip to content

Commit 6497a08

Browse files
rybosomegarrettjonesgoogle
authored andcommitted
Standardize IAM method names in Google Cloud Storage (#1906)
IAM methods in the public APIs are named getIamPolicy, setIamPolicy and testIamPermissions. Standardizing on these will reduce cognitive overhead.
1 parent 119f9c4 commit 6497a08

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/FakeStorageRpc.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,17 +448,17 @@ private static boolean processedAsFolder(StorageObject so, String delimiter, Str
448448
}
449449

450450
@Override
451-
public Policy getPolicy(String bucket) {
451+
public Policy getIamPolicy(String bucket) {
452452
throw new UnsupportedOperationException();
453453
}
454454

455455
@Override
456-
public Policy updatePolicy(String bucket, Policy policy) {
456+
public Policy setIamPolicy(String bucket, Policy policy) {
457457
throw new UnsupportedOperationException();
458458
}
459459

460460
@Override
461-
public TestIamPermissionsResponse testPermissions(String bucket, List<String> permissions) {
461+
public TestIamPermissionsResponse testIamPermissions(String bucket, List<String> permissions) {
462462
throw new UnsupportedOperationException();
463463
}
464464
}

google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,13 +2378,13 @@ public static Builder newBuilder() {
23782378
* <p>Example of getting the IAM policy for a bucket.
23792379
* <pre> {@code
23802380
* String bucketName = "my_unique_bucket";
2381-
* Policy policy = storage.getPolicy(bucketName);
2381+
* Policy policy = storage.getIamPolicy(bucketName);
23822382
* }</pre>
23832383
*
23842384
* @throws StorageException upon failure
23852385
*/
23862386
@GcpLaunchStage.Alpha
2387-
Policy getPolicy(String bucket);
2387+
Policy getIamPolicy(String bucket);
23882388

23892389
/**
23902390
* Updates the IAM policy on the specified bucket.
@@ -2393,9 +2393,9 @@ public static Builder newBuilder() {
23932393
* <pre>{@code
23942394
* // We want to make all objects in our bucket publicly readable.
23952395
* String bucketName = "my_unique_bucket";
2396-
* Policy currentPolicy = storage.getPolicy(bucketName);
2396+
* Policy currentPolicy = storage.getIamPolicy(bucketName);
23972397
* Policy updatedPolicy =
2398-
* storage.updatePolicy(
2398+
* storage.setIamPolicy(
23992399
* bucketName,
24002400
* currentPolicy.toBuilder()
24012401
* .addIdentity(StorageRoles.objectViewer(), Identity.allUsers())
@@ -2405,7 +2405,7 @@ public static Builder newBuilder() {
24052405
* @throws StorageException upon failure
24062406
*/
24072407
@GcpLaunchStage.Alpha
2408-
Policy updatePolicy(String bucket, Policy policy);
2408+
Policy setIamPolicy(String bucket, Policy policy);
24092409

24102410
/**
24112411
* Tests whether the caller holds the permissions on the specified bucket. Returns a list of
@@ -2415,7 +2415,7 @@ public static Builder newBuilder() {
24152415
* <pre> {@code
24162416
* String bucketName = "my_unique_bucket";
24172417
* List<Boolean> response =
2418-
* storage.testPermissions(
2418+
* storage.testIamPermissions(
24192419
* bucket,
24202420
* ImmutableList.of("storage.buckets.get", "storage.buckets.getIamPolicy"));
24212421
* for (boolean hasPermission : response) {
@@ -2426,5 +2426,5 @@ public static Builder newBuilder() {
24262426
* @throws StorageException upon failure
24272427
*/
24282428
@GcpLaunchStage.Alpha
2429-
List<Boolean> testPermissions(String bucket, List<String> permissions);
2429+
List<Boolean> testIamPermissions(String bucket, List<String> permissions);
24302430
}

google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -862,12 +862,12 @@ public List<ObjectAccessControl> call() {
862862
}
863863

864864
@Override
865-
public Policy getPolicy(final String bucket) {
865+
public Policy getIamPolicy(final String bucket) {
866866
try {
867867
return convertFromApiPolicy(runWithRetries(new Callable<com.google.api.services.storage.model.Policy>() {
868868
@Override
869869
public com.google.api.services.storage.model.Policy call() {
870-
return storageRpc.getPolicy(bucket);
870+
return storageRpc.getIamPolicy(bucket);
871871
}
872872
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()));
873873
} catch (RetryHelperException e){
@@ -876,12 +876,12 @@ public com.google.api.services.storage.model.Policy call() {
876876
}
877877

878878
@Override
879-
public Policy updatePolicy(final String bucket, final Policy policy) {
879+
public Policy setIamPolicy(final String bucket, final Policy policy) {
880880
try {
881881
return convertFromApiPolicy(runWithRetries(new Callable<com.google.api.services.storage.model.Policy>() {
882882
@Override
883883
public com.google.api.services.storage.model.Policy call() {
884-
return storageRpc.updatePolicy(bucket, convertToApiPolicy(policy));
884+
return storageRpc.setIamPolicy(bucket, convertToApiPolicy(policy));
885885
}
886886
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()));
887887
} catch (RetryHelperException e) {
@@ -890,12 +890,12 @@ public com.google.api.services.storage.model.Policy call() {
890890
}
891891

892892
@Override
893-
public List<Boolean> testPermissions(final String bucket, final List<String> permissions) {
893+
public List<Boolean> testIamPermissions(final String bucket, final List<String> permissions) {
894894
try {
895895
TestIamPermissionsResponse response = runWithRetries(new Callable<TestIamPermissionsResponse>() {
896896
@Override
897897
public TestIamPermissionsResponse call() {
898-
return storageRpc.testPermissions(bucket, permissions);
898+
return storageRpc.testIamPermissions(bucket, permissions);
899899
}
900900
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock());
901901
final Set<String> heldPermissions =

google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ public List<ObjectAccessControl> listAcls(String bucket, String object, Long gen
838838
}
839839

840840
@Override
841-
public Policy getPolicy(String bucket) {
841+
public Policy getIamPolicy(String bucket) {
842842
try {
843843
return storage.buckets().getIamPolicy(bucket).execute();
844844
} catch (IOException ex) {
@@ -847,7 +847,7 @@ public Policy getPolicy(String bucket) {
847847
}
848848

849849
@Override
850-
public Policy updatePolicy(String bucket, Policy policy) {
850+
public Policy setIamPolicy(String bucket, Policy policy) {
851851
try {
852852
return storage.buckets().setIamPolicy(bucket, policy).execute();
853853
} catch (IOException ex) {
@@ -856,7 +856,7 @@ public Policy updatePolicy(String bucket, Policy policy) {
856856
}
857857

858858
@Override
859-
public TestIamPermissionsResponse testPermissions(String bucket, List<String> permissions) {
859+
public TestIamPermissionsResponse testIamPermissions(String bucket, List<String> permissions) {
860860
try {
861861
return storage.buckets().testIamPermissions(bucket, permissions).execute();
862862
} catch (IOException ex) {

google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/StorageRpc.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,19 +435,19 @@ void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset,
435435
*
436436
* @throws StorageException upon failure
437437
*/
438-
Policy getPolicy(String bucket);
438+
Policy getIamPolicy(String bucket);
439439

440440
/**
441441
* Updates the IAM policy for the specified bucket.
442442
*
443443
* @throws StorageException upon failure
444444
*/
445-
Policy updatePolicy(String bucket, Policy policy);
445+
Policy setIamPolicy(String bucket, Policy policy);
446446

447447
/**
448448
* Tests whether the caller holds the specified permissions for the specified bucket.
449449
*
450450
* @throws StorageException upon failure
451451
*/
452-
TestIamPermissionsResponse testPermissions(String bucket, List<String> permissions);
452+
TestIamPermissionsResponse testIamPermissions(String bucket, List<String> permissions);
453453
}

google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,15 +1983,15 @@ public void testListBlobAcl() {
19831983
}
19841984

19851985
@Test
1986-
public void testGetPolicy() {
1987-
EasyMock.expect(storageRpcMock.getPolicy(BUCKET_NAME1)).andReturn(API_POLICY1);
1986+
public void testGetIamPolicy() {
1987+
EasyMock.expect(storageRpcMock.getIamPolicy(BUCKET_NAME1)).andReturn(API_POLICY1);
19881988
EasyMock.replay(storageRpcMock);
19891989
initializeService();
1990-
assertEquals(LIB_POLICY1, storage.getPolicy(BUCKET_NAME1));
1990+
assertEquals(LIB_POLICY1, storage.getIamPolicy(BUCKET_NAME1));
19911991
}
19921992

19931993
@Test
1994-
public void testUpdatePolicy() {
1994+
public void testSetIamPolicy() {
19951995
com.google.api.services.storage.model.Policy preCommitApiPolicy =
19961996
new com.google.api.services.storage.model.Policy()
19971997
.setBindings(ImmutableList.of(
@@ -2036,18 +2036,18 @@ public void testUpdatePolicy() {
20362036
.setEtag(POLICY_ETAG2)
20372037
.build();
20382038

2039-
EasyMock.expect(storageRpcMock.getPolicy(BUCKET_NAME1)).andReturn(API_POLICY1);
2039+
EasyMock.expect(storageRpcMock.getIamPolicy(BUCKET_NAME1)).andReturn(API_POLICY1);
20402040
EasyMock.expect(
2041-
storageRpcMock.updatePolicy(
2041+
storageRpcMock.setIamPolicy(
20422042
eq(BUCKET_NAME1),
20432043
eqApiPolicy(preCommitApiPolicy)))
20442044
.andReturn(postCommitApiPolicy);
20452045
EasyMock.replay(storageRpcMock);
20462046
initializeService();
20472047

2048-
Policy currentPolicy = storage.getPolicy(BUCKET_NAME1);
2048+
Policy currentPolicy = storage.getIamPolicy(BUCKET_NAME1);
20492049
Policy updatedPolicy =
2050-
storage.updatePolicy(
2050+
storage.setIamPolicy(
20512051
BUCKET_NAME1,
20522052
currentPolicy.toBuilder()
20532053
.addIdentity(StorageRoles.admin(), Identity.group("test-group@gmail.com"))
@@ -2056,30 +2056,30 @@ public void testUpdatePolicy() {
20562056
}
20572057

20582058
@Test
2059-
public void testTestPermissionsNull() {
2059+
public void testTestIamPermissionsNull() {
20602060
ImmutableList<Boolean> expectedPermissions = ImmutableList.of(false, false, false);
20612061
ImmutableList<String> checkedPermissions =
20622062
ImmutableList.of("storage.buckets.get", "storage.buckets.getIamPolicy", "storage.objects.list");
20632063

2064-
EasyMock.expect(storageRpcMock.testPermissions(BUCKET_NAME1, checkedPermissions))
2064+
EasyMock.expect(storageRpcMock.testIamPermissions(BUCKET_NAME1, checkedPermissions))
20652065
.andReturn(new TestIamPermissionsResponse());
20662066
EasyMock.replay(storageRpcMock);
20672067
initializeService();
2068-
assertEquals(expectedPermissions, storage.testPermissions(BUCKET_NAME1, checkedPermissions));
2068+
assertEquals(expectedPermissions, storage.testIamPermissions(BUCKET_NAME1, checkedPermissions));
20692069
}
20702070

20712071
@Test
2072-
public void testTestPermissionsNonNull() {
2072+
public void testTestIamPermissionsNonNull() {
20732073
ImmutableList<Boolean> expectedPermissions = ImmutableList.of(true, false, true);
20742074
ImmutableList<String> checkedPermissions =
20752075
ImmutableList.of("storage.buckets.get", "storage.buckets.getIamPolicy", "storage.objects.list");
20762076

2077-
EasyMock.expect(storageRpcMock.testPermissions(BUCKET_NAME1, checkedPermissions))
2077+
EasyMock.expect(storageRpcMock.testIamPermissions(BUCKET_NAME1, checkedPermissions))
20782078
.andReturn(new TestIamPermissionsResponse()
20792079
.setPermissions(ImmutableList.of("storage.objects.list", "storage.buckets.get")));
20802080
EasyMock.replay(storageRpcMock);
20812081
initializeService();
2082-
assertEquals(expectedPermissions, storage.testPermissions(BUCKET_NAME1, checkedPermissions));
2082+
assertEquals(expectedPermissions, storage.testIamPermissions(BUCKET_NAME1, checkedPermissions));
20832083
}
20842084

20852085
@Test

google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,19 +1463,19 @@ public void testBucketPolicy() {
14631463
StorageRoles.legacyObjectReader(), newHashSet(Identity.allUsers()));
14641464

14651465
// Validate getting policy.
1466-
Policy currentPolicy = storage.getPolicy(BUCKET);
1466+
Policy currentPolicy = storage.getIamPolicy(BUCKET);
14671467
assertEquals(bindingsWithoutPublicRead, currentPolicy.getBindings());
14681468

14691469
// Validate updating policy.
14701470
Policy updatedPolicy =
1471-
storage.updatePolicy(
1471+
storage.setIamPolicy(
14721472
BUCKET,
14731473
currentPolicy.toBuilder()
14741474
.addIdentity(StorageRoles.legacyObjectReader(), Identity.allUsers())
14751475
.build());
14761476
assertEquals(bindingsWithPublicRead, updatedPolicy.getBindings());
14771477
Policy revertedPolicy =
1478-
storage.updatePolicy(
1478+
storage.setIamPolicy(
14791479
BUCKET,
14801480
updatedPolicy.toBuilder()
14811481
.removeIdentity(StorageRoles.legacyObjectReader(), Identity.allUsers())
@@ -1486,7 +1486,7 @@ public void testBucketPolicy() {
14861486
List<Boolean> expectedPermissions = ImmutableList.of(true, true);
14871487
assertEquals(
14881488
expectedPermissions,
1489-
storage.testPermissions(
1489+
storage.testIamPermissions(
14901490
BUCKET,
14911491
ImmutableList.of("storage.buckets.getIamPolicy", "storage.buckets.setIamPolicy")));
14921492
}

0 commit comments

Comments
 (0)