use of com.google.api.services.cloudresourcemanager.v3.model.Policy 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.cloudresourcemanager.v3.model.Policy 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.cloudresourcemanager.v3.model.Policy in project java-docs-samples by GoogleCloudPlatform.
the class RemoveMember method removeMember.
// Removes member from a role; removes binding if binding contains 0 members.
public static void removeMember(Policy policy) {
// policy = service.Projects.GetIAmPolicy(new GetIamPolicyRequest(), your-project-id).Execute();
String role = "roles/existing-role";
String member = "user:member-to-remove@example.com";
List<Binding> bindings = policy.getBindings();
Binding binding = null;
for (Binding b : bindings) {
if (b.getRole().equals(role)) {
binding = b;
}
}
if (binding.getMembers().contains(member)) {
binding.getMembers().remove(member);
System.out.println("Member " + member + " removed from " + role);
if (binding.getMembers().isEmpty()) {
policy.getBindings().remove(binding);
}
return;
}
System.out.println("Role not found in policy; member not removed");
return;
}
use of com.google.api.services.cloudresourcemanager.v3.model.Policy 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.cloudresourcemanager.v3.model.Policy in project java-docs-samples by GoogleCloudPlatform.
the class AccessTests method beforeTest.
@Before
public void beforeTest() {
bout = new ByteArrayOutputStream();
System.setOut(new PrintStream(bout));
policyMock = new Policy();
List<String> members = new ArrayList<String>();
members.add("user:member-to-remove@example.com");
Binding binding = new Binding();
binding.setRole("roles/existing-role");
binding.setMembers(members);
List<Binding> bindings = new ArrayList<Binding>();
bindings.add(binding);
policyMock.setBindings(bindings);
}
Aggregations