private async void OnAddCredentialsCommand() { var request = AddWindowsCredentialWindow.PromptUser(_instance); if (request == null) { return; } WindowsInstanceCredentials credentials; if (request.GeneratePassword) { var resetCredentialsTask = CreateOrResetCredentials(request.User); credentials = await ProgressDialogWindow.PromptUser( resetCredentialsTask, new ProgressDialogWindow.Options { Title = Resources.ResetPasswordProgressTitle, Message = String.Format(Resources.ResetPasswordProgressMessage, request.User), IsCancellable = false }); if (credentials != null) { ShowPasswordWindow.PromptUser( new ShowPasswordWindow.Options { Title = String.Format(Resources.ShowPasswordWindowTitle, _instance.Name), Message = String.Format(Resources.ShowPasswordNewPasswordMessage, credentials.User), Password = credentials.Password, }); } } else { credentials = new WindowsInstanceCredentials { User = request.User, Password = request.Password }; } if (credentials != null) { WindowsCredentialsStore.Default.AddCredentialsToInstance(_instance, credentials); CredentialsList = WindowsCredentialsStore.Default.GetCredentialsForInstance(_instance); EventsReporterWrapper.ReportEvent(AddWindowsCredentialEvent.Create()); } }
private async void OnOkCommand() { if (!UserPromptUtils.YesNoPrompt( String.Format(Resources.ResetPasswordConfirmationPromptMessage, UserName, _instance.Name), Resources.ResetPasswordConfirmationPromptTitle)) { Debug.WriteLine("The user cancelled resetting the password."); return; } try { Debug.WriteLine($"Resetting the password for the user {UserName}"); ResettingPassword = true; // The operation cannot be cancelled once it started, so we have to disable the buttons while // it is in flight. OkCommand.CanExecuteCommand = false; CancelCommand.CanExecuteCommand = false; _owner.IsCloseButtonEnabled = false; // Check that gcloud is in the right state to invoke the reset credentials method. if (!await GCloudWrapper.CanUseResetWindowsCredentialsAsync()) { if (!GCloudWrapper.IsGCloudCliInstalled()) { LinkPromptDialogWindow.PromptUser( Resources.ResetPasswordMissingGcloudTitle, Resources.ResetPasswordGcloudMissingMessage, new LinkInfo(link: "https://cloud.google.com/sdk/", caption: Resources.ResetPasswordGcloudLinkCaption)); } else { UserPromptUtils.ErrorPrompt( message: Resources.ResetPasswordGcloudMissingBetaMessage, title: Resources.ResetPasswordGcloudMissingComponentTitle); } return; } var context = new Context { CredentialsPath = CredentialsStore.Default.CurrentAccountPath, ProjectId = _projectId, AppName = GoogleCloudExtensionPackage.ApplicationName, AppVersion = GoogleCloudExtensionPackage.ApplicationVersion, }; var newCredentials = await GCloudWrapper.ResetWindowsCredentialsAsync( instanceName : _instance.Name, zoneName : _instance.GetZoneName(), userName : _userName, context : context); ResettingPassword = false; ShowPasswordWindow.PromptUser( userName: UserName, password: newCredentials.Password, instanceName: _instance.Name); } catch (GCloudException ex) { UserPromptUtils.ErrorPrompt( String.Format(Resources.ResetPasswordFailedPromptMessage, _instance.Name, ex.Message), Resources.ResetPasswordConfirmationPromptTitle); } finally { _owner.Close(); } }