use of com.google.cloud.tools.intellij.project.CloudProject in project google-cloud-intellij by GoogleCloudPlatform.
the class AddCloudLibrariesDialog method doOKAction.
/**
* Overrides {@link DialogWrapper#doOKAction()} to first check if there are any APIs to enable on
* GCP.
*
* <p>If so, the {@link CloudApiManagementConfirmationDialog} is opened confirming the API changes
* to be made. If the user cancels, the user is returned to this parent dialog. Otherwise, it is
* closed and the default {@link DialogWrapper#doOKAction()} is invoked.
*/
@Override
protected void doOKAction() {
CloudProject cloudProject = getCloudProject();
Set<CloudLibrary> selectedApis = getSelectedLibraries();
Set<CloudLibrary> apisToEnable = getApisToEnable();
Set<CloudLibrary> apisNotEnabled = Sets.difference(selectedApis, apisToEnable);
if (cloudProject != null) {
Set<Role> roles = getServiceAccountRoles(selectedApis);
CloudApiManagementConfirmationDialog managementDialog = new CloudApiManagementConfirmationDialog(getSelectedModule(), cloudProject, apisToEnable, apisNotEnabled, roles);
DialogManager.show(managementDialog);
if (managementDialog.isOK()) {
if (!apisToEnable.isEmpty()) {
runApiEnablement(apisToEnable);
}
if (managementDialog.isCreateNewServiceAccount()) {
runServiceAccountManagement(managementDialog.getSelectedRoles(), managementDialog.getServiceAccountName(), managementDialog.getServiceAccountKeyDownloadPath());
}
super.doOKAction();
}
} else {
super.doOKAction();
}
}
use of com.google.cloud.tools.intellij.project.CloudProject in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudApiManager method addRolesToServiceAccount.
/**
* Adds a set of {@link Role roles} to a {@link ServiceAccount}.
*
* <p>This is done by fetching the cloud project's existing IAM Policy, adding the new roles to
* the given service account, and then writing the updated policy back to the cloud project.
*
* @param user the current {@link CredentialedUser}
* @param serviceAccount the {@link ServiceAccount} to which to add roles
* @param roles the set of {@link Role} to be added to the service account
* @param cloudProject the current {@link CloudProject}
* @throws IOException if the API call fails to update the IAM policy
*/
private static void addRolesToServiceAccount(CredentialedUser user, ServiceAccount serviceAccount, Set<Role> roles, CloudProject cloudProject) throws IOException {
CloudResourceManager resourceManager = GoogleApiClientFactory.getInstance().getCloudResourceManagerClient(user.getCredential());
Policy existingPolicy = resourceManager.projects().getIamPolicy(cloudProject.projectId(), new GetIamPolicyRequest()).execute();
List<Binding> bindings = Lists.newArrayList(existingPolicy.getBindings());
List<Binding> additionalBindings = roles.stream().map(role -> {
Binding binding = new Binding();
binding.setRole(role.getName());
binding.setMembers(createServiceAccountMemberBindings(serviceAccount));
return binding;
}).collect(Collectors.toList());
bindings.addAll(additionalBindings);
SetIamPolicyRequest policyRequest = new SetIamPolicyRequest();
Policy newPolicy = new Policy();
newPolicy.setBindings(bindings);
policyRequest.setPolicy(newPolicy);
resourceManager.projects().setIamPolicy(cloudProject.projectId(), policyRequest).execute();
}
use of com.google.cloud.tools.intellij.project.CloudProject in project google-cloud-intellij by GoogleCloudPlatform.
the class ProjectDebuggeeBinding method buildResult.
@NotNull
public CloudDebugProcessState buildResult(Project project) {
CloudProject cloudProject = projectSelector.getSelectedProject();
String projectId = Optional.ofNullable(cloudProject).map(CloudProject::projectId).orElse("");
String projectNumberString = Optional.ofNullable(cloudProject).map(CloudProject::projectNumber).map(Object::toString).orElse(null);
DebugTarget selectedItem = (DebugTarget) targetSelector.getSelectedItem();
String savedDebuggeeId = selectedItem != null ? selectedItem.getId() : null;
return new CloudDebugProcessState(credentialedUser != null ? credentialedUser.getEmail() : null, savedDebuggeeId, projectId, projectNumberString, project);
}
use of com.google.cloud.tools.intellij.project.CloudProject in project google-cloud-intellij by GoogleCloudPlatform.
the class ProjectDebuggeeBinding method getCloudDebuggerClient.
@Nullable
private Debugger getCloudDebuggerClient() {
CloudProject cloudProject = projectSelector.getSelectedProject();
CredentialedUser credentialedUser = cloudProject == null ? null : Services.getLoginService().getLoggedInUser(cloudProject.googleUsername()).orElse(null);
if (this.credentialedUser == credentialedUser) {
return cloudDebuggerClient;
}
this.credentialedUser = credentialedUser;
cloudDebuggerClient = this.credentialedUser != null ? CloudDebuggerClient.getLongTimeoutClient(this.credentialedUser.getEmail()) : null;
return cloudDebuggerClient;
}
use of com.google.cloud.tools.intellij.project.CloudProject in project google-cloud-intellij by GoogleCloudPlatform.
the class AppEngineStandardDeploymentEditorTest method resetEditorFrom_doesSet_matchingCloudProject.
@Test
public void resetEditorFrom_doesSet_matchingCloudProject() {
String projectId = "some-project";
configuration.setCloudProjectName(projectId);
configuration.setGoogleUsername(EMAIL);
editor.resetEditorFrom(configuration);
CloudProject expectedProject = CloudProject.create(projectId, projectId, EMAIL);
verify(projectSelector).setSelectedProject(expectedProject);
}
Aggregations