use of com.google.api.services.cloudresourcemanager.v3.CloudResourceManager in project java-docs-samples by GoogleCloudPlatform.
the class Quickstart method addBinding.
public static void addBinding(CloudResourceManager crmService, String projectId, String member, String role) {
// Gets the project's policy.
Policy policy = getPolicy(crmService, projectId);
// Finds binding in policy, if it exists
Binding binding = null;
for (Binding b : policy.getBindings()) {
if (b.getRole().equals(role)) {
binding = b;
break;
}
}
if (binding != null) {
// If binding already exists, adds member to binding.
binding.getMembers().add(member);
} else {
// If binding does not exist, adds binding to policy.
binding = new Binding();
binding.setRole(role);
binding.setMembers(Collections.singletonList(member));
policy.getBindings().add(binding);
}
// Sets the updated policy
setPolicy(crmService, projectId, policy);
}
use of com.google.api.services.cloudresourcemanager.v3.CloudResourceManager in project java-docs-samples by GoogleCloudPlatform.
the class Quickstart method initializeService.
public static CloudResourceManager initializeService() throws IOException, GeneralSecurityException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
GoogleCredentials credential = GoogleCredentials.getApplicationDefault().createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
// Creates the Cloud Resource Manager service object.
CloudResourceManager service = new CloudResourceManager.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), new HttpCredentialsAdapter(credential)).setApplicationName("iam-quickstart").build();
return service;
}
use of com.google.api.services.cloudresourcemanager.v3.CloudResourceManager in project java-docs-samples by GoogleCloudPlatform.
the class TestPermissions method createCloudResourceManagerService.
public static CloudResourceManager createCloudResourceManagerService() throws IOException, GeneralSecurityException {
// Use the Application Default Credentials strategy for authentication. For more info, see:
// https://cloud.google.com/docs/authentication/production#finding_credentials_automatically
GoogleCredentials credential = GoogleCredentials.getApplicationDefault().createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM));
CloudResourceManager service = new CloudResourceManager.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), new HttpCredentialsAdapter(credential)).setApplicationName("service-accounts").build();
return service;
}
Aggregations