use of com.google.cloud.Role in project google-cloud-java by GoogleCloudPlatform.
the class BucketIamSnippets method listBucketIamMembers.
/**
* Example of listing the Bucket-Level IAM Roles and Members
*/
public Policy listBucketIamMembers(String bucketName) {
// [START view_bucket_iam_members]
// Initialize a Cloud Storage client
Storage storage = StorageOptions.getDefaultInstance().getService();
// Get IAM Policy for a bucket
Policy policy = storage.getIamPolicy(bucketName);
// Print Roles and its identities
Map<Role, Set<Identity>> policyBindings = policy.getBindings();
for (Map.Entry<Role, Set<Identity>> entry : policyBindings.entrySet()) {
System.out.printf("Role: %s Identities: %s\n", entry.getKey(), entry.getValue());
}
// [END view_bucket_iam_members]
return policy;
}
use of com.google.cloud.Role in project google-cloud-java by GoogleCloudPlatform.
the class PolicyMarshaller method toPb.
@Override
protected com.google.api.services.cloudresourcemanager.model.Policy toPb(Policy policy) {
com.google.api.services.cloudresourcemanager.model.Policy policyPb = new com.google.api.services.cloudresourcemanager.model.Policy();
List<Binding> bindingPbList = new LinkedList<>();
for (Map.Entry<Role, Set<Identity>> binding : policy.getBindings().entrySet()) {
Binding bindingPb = new Binding();
bindingPb.setRole(binding.getKey().getValue());
bindingPb.setMembers(Lists.transform(new ArrayList<>(binding.getValue()), new Function<Identity, String>() {
@Override
public String apply(Identity identity) {
return IDENTITY_STR_VALUE_FUNCTION.apply(identity);
}
}));
bindingPbList.add(bindingPb);
}
policyPb.setBindings(bindingPbList);
policyPb.setEtag(policy.getEtag());
policyPb.setVersion(policy.getVersion());
return policyPb;
}
use of com.google.cloud.Role 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());
}
Aggregations