@Override protected void resetEditorFrom(@NotNull CloudDebugRunConfiguration runConfiguration) { String projectId = runConfiguration.getCloudProjectId(); // google username may be empty from previous revisions of configurations, should not be null. String googleUsername = Optional.ofNullable(runConfiguration.getGoogleUsername()).orElse(""); if (!Strings.isNullOrEmpty(projectId)) { settingsPanel.setSelectedCloudProject( CloudProject.create( // TODO(ivanporty) no project name in CloudDebugRunConfiguration. projectId /* as name */, projectId, null /* project number */, googleUsername)); } else { settingsPanel.loadActiveCloudProject(); } } }
private void loadRepositories(@Nullable Runnable onComplete) { if (cloudProject == null) { return; } Optional<CredentialedUser> user = Services.getLoginService().getLoggedInUser(cloudProject.googleUsername()); if (!user.isPresent()) { return; } if (repositories == null) { repositories = new ProjectRepositoriesModelItem(); } repositories.loadRepositories(cloudProject.projectId(), user.get(), onComplete); }
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()); } }
@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()); } }
/** * Updates component UI and state with the new project and user account information. * * @param cloudProject New project/account information, null to clear selected project. */ public void setSelectedProject(CloudProject cloudProject) { this.cloudProject = cloudProject; if (cloudProject == null || Strings.isNullOrEmpty(cloudProject.googleUsername())) { updateEmptySelection(); } else { updateCloudProjectSelection(cloudProject); } }
Services.getLoginService().getLoggedInUser(cloudProject.googleUsername()); "cloud.apis.enable.progress.message", library.getName(), cloudProject.projectName()), (double) i / libraryList.size()); enableApi(library, cloudProject, user.get()); notifyApisEnabled(enabledApis, cloudProject.projectId(), project);
@Test public void applyEditorTo_doesSetCloudProjectName() { CloudProject project = CloudProject.create("some-project", "some-project", EMAIL); when(projectSelector.getSelectedProject()).thenReturn(project); editor.applyEditorTo(configuration); assertThat(configuration.getCloudProjectName()).isEqualTo(project.projectId()); }
private void createUIComponents() { commonPanel = new ServiceAccountKeyDownloadedPanel(cloudProject.projectId(), downloadPath); runConfigurationTable = new RunConfigurationTable(); runConfigurationTable.setTableHeader(null); }
try { String projectNumber = Optional.ofNullable(cloudProject.projectNumber()) .map(Object::toString) .orElse(null); DebugTarget item = new DebugTarget(debuggee, cloudProject.projectId()); if (!Strings.isNullOrEmpty(item.getModule()) && !Strings.isNullOrEmpty(item.getVersion())) {
/** * 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 mockUserLoggedIn(String username) { when(mockLoginService.isLoggedIn()).thenReturn(true); CredentialedUser mockUser = mock(CredentialedUser.class); when(mockLoginService.getLoggedInUser(TEST_PROJECT.googleUsername())) .thenReturn(Optional.of(mockUser)); when(mockUser.getEmail()).thenReturn(username); } }
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 launchDialog(List<RunnerAndConfigurationSettings> configurationSettingsList) { when(mockCloudProject.projectId()).thenReturn("gcpProjectId"); ApplicationManager.getApplication() .invokeAndWait( () -> dialog = new ServiceAccountKeyDisplayDialog( testFixture.getProject(), mockCloudProject, "downloadPath")); dialog.initTableModel(configurationSettingsList); } }
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(); }
@Override protected void doOKAction() { CloudProject selectedProject = projectSelector.getSelectedProject(); projectId = selectedProject.projectId(); repositoryId = repositorySelector.getText(); remoteName = remoteNameSelector.getText(); credentialedUser = Services.getLoginService().getLoggedInUser(selectedProject.googleUsername()).orElse(null); super.doOKAction(); } }
@Nullable CloudProject getActiveCloudProject(@NotNull Project ideProject) { PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(ideProject); String projectAccount = propertiesComponent.getValue(PROJECT_ACCOUNT_KEY); String projectName = propertiesComponent.getValue(PROJECT_NAME_KEY); String projectId = propertiesComponent.getValue(PROJECT_ID_KEY); String projectNumberString = propertiesComponent.getValue(PROJECT_NUMBER_KEY); // we only need ID and account to show project in case it was not saved completely. if (!Strings.isNullOrEmpty(projectAccount) && !Strings.isNullOrEmpty(projectId)) { // null project number is acceptable Long projectNumber = Longs.tryParse(Strings.nullToEmpty(projectNumberString)); return CloudProject.create(projectName, projectId, projectNumber, projectAccount); } return null; } }
@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; }
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(); } }
resourceManager .projects() .getIamPolicy(cloudProject.projectId(), new GetIamPolicyRequest()) .execute(); List<Binding> bindings = Lists.newArrayList(existingPolicy.getBindings()); policyRequest.setPolicy(newPolicy); resourceManager.projects().setIamPolicy(cloudProject.projectId(), policyRequest).execute();
"cloud.apis.management.dialog.apistoenable.header", cloudProject.projectName())); wontEnableConfirmationLabel.setText( GoogleCloudApisMessageBundle.message(