@VisibleForTesting void setSelectedProject(CloudProject cloudProject) { if (cloudProject != null && !Strings.isNullOrEmpty(cloudProject.googleUsername())) { Optional<CredentialedUser> loggedInUser = Services.getLoginService().getLoggedInUser(cloudProject.googleUsername()); if (loggedInUser.isPresent()) { selectedProjectsByAccount.put(loggedInUser.get(), cloudProject.projectName()); accountComboBox.setSelectedItem(loggedInUser.get()); } } else { // no project set, show active user projects by default. accountComboBox.setSelectedItem(Services.getLoginService().getActiveUser()); } }
/** * Writes the service account private key data in JSON form to the filesystem. The private key * itself is contained within the {@link ServiceAccountKey} returned from the IAM API. The json * key is encoded within {@link ServiceAccountKey#getPrivateKeyData()} in base64. * * @param key the {@link ServiceAccountKey} containing the base64 encoding of the json private key * @param downloadDir the {@link Path} on the file system to download the ky * @param cloudProject the {@link CloudProject} associated with this service account * @return the {@link Path} to the service account key that was written * @throws IOException if the an IO error occurs when writing the file */ private static Path writeServiceAccountKey( ServiceAccountKey key, Path downloadDir, CloudProject cloudProject) throws IOException { Path keyPath = Paths.get(downloadDir.toString(), getServiceAccountKeyName(cloudProject.projectName())); return Files.write(keyPath, Base64.decodeBase64(key.getPrivateKeyData())); }
private void updateRepositorySelector(@NotNull CloudProject selectedProject) { if (defaultDirectoryName.equals(directoryName.getText()) || directoryName.getText().length() == 0) { // modify field if it was unmodified or blank String projectDescription = selectedProject.projectName(); if (!Strings.isNullOrEmpty(projectDescription)) { defaultDirectoryName = projectDescription.replaceAll(INVALID_FILENAME_CHARS, ""); defaultDirectoryName = defaultDirectoryName.replaceAll("\\s", ""); } else { defaultDirectoryName = ""; } directoryName.setText(defaultDirectoryName); } repositorySelector.setCloudProject(selectedProject); repositorySelector.setText(""); repositorySelector.loadRepositories(); updateButtons(); }
void setActiveCloudProject( @NotNull CloudProject activeCloudProject, @NotNull Project ideProject) { PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(ideProject); propertiesComponent.setValue(PROJECT_ACCOUNT_KEY, activeCloudProject.googleUsername()); propertiesComponent.setValue(PROJECT_NAME_KEY, activeCloudProject.projectName()); propertiesComponent.setValue(PROJECT_ID_KEY, activeCloudProject.projectId()); if (activeCloudProject.projectNumber() != null) { propertiesComponent.setValue( PROJECT_NUMBER_KEY, activeCloudProject.projectNumber().toString()); } }
"cloud.apis.management.dialog.apistoenable.header", cloudProject.projectName())); wontEnableConfirmationLabel.setText( GoogleCloudApisMessageBundle.message(
"cloud.apis.enable.progress.message", library.getName(), cloudProject.projectName()), (double) i / libraryList.size()); enableApi(library, cloudProject, user.get());
private void updateCloudProjectSelection(CloudProject selection) { projectNameLabel.setHyperlinkText(selection.projectName()); projectAccountSeparatorLabel.setVisible(true); // first just show account email, then expand with name/picture if this account is signed in. // if not signed in, hide icon and account name completely and prompt to sign in. accountInfoLabel.setHyperlinkText(selection.googleUsername()); IntegratedGoogleLoginService loginService = Services.getLoginService(); Optional<CredentialedUser> loggedInUser = loginService.getLoggedInUser(selection.googleUsername()); if (!loggedInUser.isPresent()) { accountInfoLabel.setHyperlinkText( GoogleCloudCoreMessageBundle.message( "cloud.project.selector.not.signed.in", selection.googleUsername())); } else if (loggedInUser.isPresent()) { accountInfoLabel.setHyperlinkText( String.format( "%s (%s)", Strings.nullToEmpty(loggedInUser.get().getName()), loggedInUser.get().getEmail())); } accountInfoLabel.setIcon( loginService.isLoggedIn() ? GoogleLoginIcons.getScaledUserIcon(ACCOUNT_ICON_SIZE, loggedInUser.orElse(null)) : null); }
private void verifyUiStateForProject(CloudProject project) { if (project == null) { assertThat(projectSelector.getProjectNameLabel().getHyperlinkText()) .isEqualTo( GoogleCloudCoreMessageBundle.getString("cloud.project.selector.no.selected.project")); // no account information UI is visible/populated. assertThat(projectSelector.getProjectAccountSeparatorLabel().isVisible()).isFalse(); assertThat(projectSelector.getAccountInfoLabel().getHyperlinkText()).isEmpty(); assertThat(projectSelector.getAccountInfoLabel().getIcon()).isNull(); } else { assertThat(projectSelector.getProjectNameLabel().getHyperlinkText()) .isEqualTo(project.projectName()); assertThat(projectSelector.getProjectAccountSeparatorLabel().isVisible()).isTrue(); assertThat(projectSelector.getAccountInfoLabel().getHyperlinkText()) .contains(project.googleUsername()); assertThat(projectSelector.getAccountInfoLabel().getIcon()).isNotNull(); } }