use of com.google.api.services.iam.v1.model.Policy in project java-docs-samples by GoogleCloudPlatform.
the class Quickstart method removeMember.
public static void removeMember(CloudResourceManager crmService, String projectId, String member, String role) {
// Gets the project's policy.
Policy policy = getPolicy(crmService, projectId);
// Removes the member from the role.
Binding binding = null;
for (Binding b : policy.getBindings()) {
if (b.getRole().equals(role)) {
binding = b;
break;
}
}
if (binding.getMembers().contains(member)) {
binding.getMembers().remove(member);
if (binding.getMembers().isEmpty()) {
policy.getBindings().remove(binding);
}
}
// Sets the updated policy.
setPolicy(crmService, projectId, policy);
}
use of com.google.api.services.iam.v1.model.Policy in project java-docs-samples by GoogleCloudPlatform.
the class DicomStoreGetIamPolicy method dicomStoreGetIamPolicy.
public static void dicomStoreGetIamPolicy(String dicomStoreName) throws IOException {
// String dicomStoreName =
// String.format(
// DICOM_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-dicom-id");
// Initialize the client, which will be used to interact with the service.
CloudHealthcare client = createClient();
// Create request and configure any parameters.
DicomStores.GetIamPolicy request = client.projects().locations().datasets().dicomStores().getIamPolicy(dicomStoreName);
// Execute the request and process the results.
Policy policy = request.execute();
System.out.println("DICOM store IAMPolicy retrieved: \n" + policy.toPrettyString());
}
use of com.google.api.services.iam.v1.model.Policy in project java-docs-samples by GoogleCloudPlatform.
the class FhirStoreSetIamPolicy method fhirStoreSetIamPolicy.
public static void fhirStoreSetIamPolicy(String fhirStoreName) throws IOException {
// String fhirStoreName =
// String.format(
// FHIR_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-fhir-id");
// Initialize the client, which will be used to interact with the service.
CloudHealthcare client = createClient();
// Configure the IAMPolicy to apply to the store.
// For more information on understanding IAM roles, see the following:
// https://cloud.google.com/iam/docs/understanding-roles
Binding binding = new Binding().setRole("roles/healthcare.fhirResourceReader").setMembers(Arrays.asList("domain:google.com"));
Policy policy = new Policy().setBindings(Arrays.asList(binding));
SetIamPolicyRequest policyRequest = new SetIamPolicyRequest().setPolicy(policy);
// Create request and configure any parameters.
FhirStores.SetIamPolicy request = client.projects().locations().datasets().fhirStores().setIamPolicy(fhirStoreName, policyRequest);
// Execute the request and process the results.
Policy updatedPolicy = request.execute();
System.out.println("FHIR policy has been updated: " + updatedPolicy.toPrettyString());
}
use of com.google.api.services.iam.v1.model.Policy in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method getKeyRingPolicy.
// [END kms_get_cryptokey_policy]
// [START kms_get_keyring_policy]
/**
* Retrieves the IAM policy for the given crypto key.
*/
public static Policy getKeyRingPolicy(String projectId, String locationId, String keyRingId) throws IOException {
// Create the Cloud KMS client.
CloudKMS kms = createAuthorizedClient();
// The resource name of the keyring
String keyring = String.format("projects/%s/locations/%s/keyRings/%s", projectId, locationId, keyRingId);
// Get the current IAM policy and add the new account to it.
Policy iamPolicy = kms.projects().locations().keyRings().getIamPolicy(keyring).execute();
System.out.println(iamPolicy.getBindings());
return iamPolicy;
}
use of com.google.api.services.iam.v1.model.Policy in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method getCryptoKeyPolicy.
// [END kms_restore_cryptokey_version]
// [START kms_get_cryptokey_policy]
/**
* Retrieves the IAM policy for the given crypto key.
*/
public static Policy getCryptoKeyPolicy(String projectId, String locationId, String keyRingId, String cryptoKeyId) throws IOException {
// Create the Cloud KMS client.
CloudKMS kms = createAuthorizedClient();
// The resource name of the cryptoKey
String cryptoKey = String.format("projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s", projectId, locationId, keyRingId, cryptoKeyId);
// Get the current IAM policy and add the new account to it.
Policy iamPolicy = kms.projects().locations().keyRings().cryptoKeys().getIamPolicy(cryptoKey).execute();
System.out.println(iamPolicy.getBindings());
return iamPolicy;
}
Aggregations