use of com.google.api.services.healthcare.v1.model.SetIamPolicyRequest in project java-docs-samples by GoogleCloudPlatform.
the class DatasetSetIamPolicy method datasetSetIamPolicy.
public static void datasetSetIamPolicy(String datasetName) throws IOException {
// String datasetName =
// String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-dataset-id");
// Initialize the client, which will be used to interact with the service.
CloudHealthcare client = createClient();
// Configure the IAMPolicy to apply to the dataset.
// 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.datasetViewer").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.
Datasets.SetIamPolicy request = client.projects().locations().datasets().setIamPolicy(datasetName, policyRequest);
// Execute the request and process the results.
Policy updatedPolicy = request.execute();
System.out.println("Dataset policy has been updated: " + updatedPolicy.toPrettyString());
}
use of com.google.api.services.healthcare.v1.model.SetIamPolicyRequest in project java-docs-samples by GoogleCloudPlatform.
the class DicomStoreSetIamPolicy method dicomStoreSetIamPolicy.
public static void dicomStoreSetIamPolicy(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();
// 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.dicomStoreAdmin").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.
DicomStores.SetIamPolicy request = client.projects().locations().datasets().dicomStores().setIamPolicy(dicomStoreName, policyRequest);
// Execute the request and process the results.
Policy updatedPolicy = request.execute();
System.out.println("DICOM policy has been updated: " + updatedPolicy.toPrettyString());
}
use of com.google.api.services.healthcare.v1.model.SetIamPolicyRequest in project java-docs-samples by GoogleCloudPlatform.
the class SetPolicy method setPolicy.
// Sets a project's policy.
public static void setPolicy(Policy policy, String projectId) {
// policy = service.Projects.GetIAmPolicy(new GetIamPolicyRequest(), your-project-id).Execute();
// projectId = "my-project-id"
CloudResourceManager service = null;
try {
service = createCloudResourceManagerService();
} catch (IOException | GeneralSecurityException e) {
System.out.println("Unable to initialize service: \n" + e.toString());
return;
}
try {
SetIamPolicyRequest request = new SetIamPolicyRequest();
request.setPolicy(policy);
Policy response = service.projects().setIamPolicy(projectId, request).execute();
System.out.println("Policy set: " + response.toString());
} catch (IOException e) {
System.out.println("Unable to set policy: \n" + e.toString());
}
}
use of com.google.api.services.healthcare.v1.model.SetIamPolicyRequest in project terra-workspace-manager by DataBiosphere.
the class GcpCloudSyncStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException, RetryException {
String gcpProjectId = flightContext.getWorkingMap().get(GCP_PROJECT_ID, String.class);
FlightMap workingMap = flightContext.getWorkingMap();
// Read Sam groups for each workspace role.
Map<WsmIamRole, String> workspaceRoleGroupsMap = workingMap.get(WorkspaceFlightMapKeys.IAM_GROUP_EMAIL_MAP, new TypeReference<>() {
});
try {
Policy currentPolicy = resourceManagerCow.projects().getIamPolicy(gcpProjectId, new GetIamPolicyRequest()).execute();
List<Binding> newBindings = new ArrayList<>();
// Add all existing bindings to ensure we don't accidentally clobber existing permissions.
newBindings.addAll(currentPolicy.getBindings());
// Add appropriate project-level roles for each WSM IAM role.
workspaceRoleGroupsMap.forEach((role, email) -> newBindings.add(bindingForRole(role, email, gcpProjectId)));
Policy newPolicy = new Policy().setVersion(currentPolicy.getVersion()).setBindings(newBindings).setEtag(currentPolicy.getEtag());
SetIamPolicyRequest iamPolicyRequest = new SetIamPolicyRequest().setPolicy(newPolicy);
logger.info("Setting new Cloud Context IAM policy: " + iamPolicyRequest.toPrettyString());
resourceManagerCow.projects().setIamPolicy(gcpProjectId, iamPolicyRequest).execute();
} catch (IOException e) {
throw new RetryableCrlException("Error setting IAM permissions", e);
}
return StepResult.getStepResultSuccess();
}
use of com.google.api.services.healthcare.v1.model.SetIamPolicyRequest in project terra-workspace-manager by DataBiosphere.
the class GrantWsmRoleAdminStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
String wsmSaEmail = GcpUtils.getWsmSaEmail(crlService.getApplicationCredentials());
String projectId = context.getWorkingMap().get(WorkspaceFlightMapKeys.GCP_PROJECT_ID, String.class);
try {
Policy policy = crlService.getCloudResourceManagerCow().projects().getIamPolicy(projectId, new GetIamPolicyRequest()).execute();
Binding bindingToAdd = new Binding().setMembers(Collections.singletonList("serviceAccount:" + wsmSaEmail)).setRole("roles/iam.roleAdmin");
List<Binding> bindingList = policy.getBindings();
bindingList.add(bindingToAdd);
policy.setBindings(bindingList);
SetIamPolicyRequest iamPolicyRequest = new SetIamPolicyRequest().setPolicy(policy);
crlService.getCloudResourceManagerCow().projects().setIamPolicy(projectId, iamPolicyRequest).execute();
} catch (IOException e) {
throw new InternalServerErrorException("Error while granting WSM SA the Role Admin role", e);
}
return StepResult.getStepResultSuccess();
}
Aggregations