private async Task <WindowsInstanceCredentials> CreateOrResetCredentials(string user) { try { Debug.WriteLine("The user requested the password to be generated."); if (!UserPromptUtils.ActionPrompt( prompt: String.Format(Resources.ResetPasswordConfirmationPromptMessage, user, _instance.Name), title: Resources.ResetPasswordConfirmationPromptTitle, message: Resources.UiOperationCannotBeUndone, actionCaption: Resources.UiResetButtonCaption, isWarning: true)) { Debug.WriteLine("The user cancelled resetting the password."); return(null); } Debug.WriteLine($"Resetting the password for the user {user}"); // Check that gcloud is in the right state to invoke the reset credentials method. if (!await VerifyGCloudDependencies()) { Debug.WriteLine("Missing gcloud dependencies for resetting password."); return(null); } var context = new GCloudContext { CredentialsPath = CredentialsStore.Default.CurrentAccountPath, ProjectId = CredentialsStore.Default.CurrentProjectId, AppName = GoogleCloudExtensionPackage.ApplicationName, AppVersion = GoogleCloudExtensionPackage.ApplicationVersion, }; return(await GCloudWrapper.ResetWindowsCredentialsAsync( instanceName : _instance.Name, zoneName : _instance.GetZoneName(), userName : user, context : context)); } catch (GCloudException ex) { UserPromptUtils.ErrorPrompt( message: String.Format(Resources.ResetPasswordFailedPromptMessage, _instance.Name), title: Resources.ResetPasswordConfirmationPromptTitle, errorDetails: ex.Message); return(null); } }
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(); } }