use of com.google.api.services.storage.model.Policy.Bindings in project google-cloud-java by GoogleCloudPlatform.
the class StorageImplTest method testSetIamPolicy.
@Test
public void testSetIamPolicy() {
com.google.api.services.storage.model.Policy preCommitApiPolicy = new com.google.api.services.storage.model.Policy().setBindings(ImmutableList.of(new Bindings().setMembers(ImmutableList.of("allUsers")).setRole("roles/storage.objectViewer"), new Bindings().setMembers(ImmutableList.of("user:test1@gmail.com", "user:test2@gmail.com")).setRole("roles/storage.objectAdmin"), new Bindings().setMembers(ImmutableList.of("group:test-group@gmail.com")).setRole("roles/storage.admin"))).setEtag(POLICY_ETAG1);
// postCommitApiPolicy is identical but for the etag, which has been updated.
com.google.api.services.storage.model.Policy postCommitApiPolicy = new com.google.api.services.storage.model.Policy().setBindings(ImmutableList.of(new Bindings().setMembers(ImmutableList.of("allUsers")).setRole("roles/storage.objectViewer"), new Bindings().setMembers(ImmutableList.of("user:test1@gmail.com", "user:test2@gmail.com")).setRole("roles/storage.objectAdmin"), new Bindings().setMembers(ImmutableList.of("group:test-group@gmail.com")).setRole("roles/storage.admin"))).setEtag(POLICY_ETAG2);
Policy postCommitLibPolicy = Policy.newBuilder().addIdentity(StorageRoles.objectViewer(), Identity.allUsers()).addIdentity(StorageRoles.objectAdmin(), Identity.user("test1@gmail.com"), Identity.user("test2@gmail.com")).addIdentity(StorageRoles.admin(), Identity.group("test-group@gmail.com")).setEtag(POLICY_ETAG2).build();
EasyMock.expect(storageRpcMock.getIamPolicy(BUCKET_NAME1)).andReturn(API_POLICY1);
EasyMock.expect(storageRpcMock.setIamPolicy(eq(BUCKET_NAME1), eqApiPolicy(preCommitApiPolicy))).andReturn(postCommitApiPolicy);
EasyMock.replay(storageRpcMock);
initializeService();
Policy currentPolicy = storage.getIamPolicy(BUCKET_NAME1);
Policy updatedPolicy = storage.setIamPolicy(BUCKET_NAME1, currentPolicy.toBuilder().addIdentity(StorageRoles.admin(), Identity.group("test-group@gmail.com")).build());
assertEquals(updatedPolicy, postCommitLibPolicy);
}
use of com.google.api.services.storage.model.Policy.Bindings in project google-cloud-java by GoogleCloudPlatform.
the class PolicyHelper method convertToApiPolicy.
static com.google.api.services.storage.model.Policy convertToApiPolicy(Policy policy) {
List<Bindings> bindings = new ArrayList<>(policy.getBindings().size());
for (Map.Entry<Role, Set<Identity>> entry : policy.getBindings().entrySet()) {
List<String> members = new ArrayList<>(entry.getValue().size());
for (Identity identity : entry.getValue()) {
members.add(identity.strValue());
}
bindings.add(new Bindings().setMembers(members).setRole(entry.getKey().getValue()));
}
return new com.google.api.services.storage.model.Policy().setBindings(bindings).setEtag(policy.getEtag());
}
use of com.google.api.services.storage.model.Policy.Bindings in project google-cloud-java by GoogleCloudPlatform.
the class PolicyHelperTest method testEquivalence.
@Test
public void testEquivalence() {
Policy libPolicy = Policy.newBuilder().addIdentity(StorageRoles.objectViewer(), Identity.allUsers()).addIdentity(StorageRoles.objectAdmin(), Identity.user("test1@gmail.com"), Identity.user("test2@gmail.com")).setEtag(ETAG).build();
com.google.api.services.storage.model.Policy apiPolicy = new com.google.api.services.storage.model.Policy().setBindings(ImmutableList.of(new Bindings().setMembers(ImmutableList.of("allUsers")).setRole("roles/storage.objectViewer"), new Bindings().setMembers(ImmutableList.of("user:test1@gmail.com", "user:test2@gmail.com")).setRole("roles/storage.objectAdmin"))).setEtag(ETAG);
Policy actualLibPolicy = PolicyHelper.convertFromApiPolicy(apiPolicy);
com.google.api.services.storage.model.Policy actualApiPolicy = PolicyHelper.convertToApiPolicy(libPolicy);
assertEquals(libPolicy, actualLibPolicy);
assertTrue(new ApiPolicyMatcher(apiPolicy).matches(actualApiPolicy));
}
Aggregations