Search in sources :

Example 1 with CreateServiceAccountRequest

use of com.google.api.services.iam.v1.model.CreateServiceAccountRequest in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudApiManager method createServiceAccount.

/**
 * Creates a new {@link ServiceAccount} for the given {@link CloudProject} using the IAM API.
 */
private static ServiceAccount createServiceAccount(CredentialedUser user, String name, CloudProject cloudProject) throws IOException {
    CreateServiceAccountRequest request = new CreateServiceAccountRequest();
    ServiceAccount serviceAccount = new ServiceAccount();
    serviceAccount.setDisplayName(name);
    request.setServiceAccount(serviceAccount);
    request.setAccountId(createServiceAccountId(name));
    Iam iam = GoogleApiClientFactory.getInstance().getIamClient(user.getCredential());
    return iam.projects().serviceAccounts().create(String.format(SERVICE_ACCOUNT_CREATE_REQUEST_PROJECT_FORMAT, cloudProject.projectId()), request).execute();
}
Also used : ServiceAccount(com.google.api.services.iam.v1.model.ServiceAccount) Iam(com.google.api.services.iam.v1.Iam) CreateServiceAccountRequest(com.google.api.services.iam.v1.model.CreateServiceAccountRequest)

Aggregations

Iam (com.google.api.services.iam.v1.Iam)1 CreateServiceAccountRequest (com.google.api.services.iam.v1.model.CreateServiceAccountRequest)1 ServiceAccount (com.google.api.services.iam.v1.model.ServiceAccount)1