use of com.google.api.services.iam.v1.model.ServiceAccountKey in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudApiManager method createServiceAccountKey.
/**
* Using the supplied {@link ServiceAccount}, this creates and returns a new {@link
* ServiceAccountKey}.
*/
private static ServiceAccountKey createServiceAccountKey(CredentialedUser user, ServiceAccount serviceAccount) throws IOException {
Iam iam = GoogleApiClientFactory.getInstance().getIamClient(user.getCredential());
CreateServiceAccountKeyRequest keyRequest = new CreateServiceAccountKeyRequest();
return iam.projects().serviceAccounts().keys().create(serviceAccount.getName(), keyRequest).execute();
}
use of com.google.api.services.iam.v1.model.ServiceAccountKey in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudApiManagerTest method setupFakeServiceAccountKey.
private void setupFakeServiceAccountKey() {
serviceAccountKey = new ServiceAccountKey();
serviceAccountKey.setPrivateKeyData("data");
}
use of com.google.api.services.iam.v1.model.ServiceAccountKey in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudApiManager method createServiceAccountAndDownloadKey.
/**
* Creates a new {@link ServiceAccount}, adds the supplied set of {@link Role roles} to it, and
* creates and downloads the service account private key to the user's file system.
*
* @param roles the set of {@link Role} to add to the new service account
* @param name the name of the new service account to be created
* @param downloadDir the {@link Path} of the download directory of the service account private
* key json file
* @param cloudProject the current {@link CloudProject}
* @param project the current {@link Project}
*/
static void createServiceAccountAndDownloadKey(Set<Role> roles, String name, Path downloadDir, CloudProject cloudProject, Project project) {
Optional<CredentialedUser> user = Services.getLoginService().getLoggedInUser(cloudProject.googleUsername());
if (!user.isPresent()) {
LOG.error("Cannot enable APIs: logged in user not found.");
return;
}
ProgressIndicator progress = ServiceManager.getService(ProgressManager.class).getProgressIndicator();
try {
int numSteps = roles.isEmpty() ? 3 : 4;
double step = 0;
updateProgress(progress, GctBundle.message("cloud.apis.service.account.create.account.progress.message", name), step / numSteps);
step++;
ServiceAccount serviceAccount = createServiceAccount(user.get(), name, cloudProject);
if (!roles.isEmpty()) {
updateProgress(progress, GctBundle.message("cloud.apis.service.account.add.roles.progress.message"), step / numSteps);
step++;
addRolesToServiceAccount(user.get(), serviceAccount, roles, cloudProject);
}
updateProgress(progress, GctBundle.message("cloud.apis.service.account.create.key.progress.message"), step / numSteps);
step++;
ServiceAccountKey serviceAccountKey = createServiceAccountKey(user.get(), serviceAccount);
updateProgress(progress, GctBundle.message("cloud.apis.service.account.download.key.progress.message"), step / numSteps);
Path keyPath = writeServiceAccountKey(serviceAccountKey, downloadDir, cloudProject);
notifyServiceAccountCreated(project, name, keyPath);
} catch (IOException e) {
LOG.warn("Exception occurred attempting to create service account on GCP and download its key", e);
notifyServiceAccountError(project, name, e.toString());
}
}
Aggregations