Example #1
0
        private async Task <bool> VerifyGCloudDependencies()
        {
            if (!await GCloudWrapper.CanUseGKEAsync())
            {
                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.GkePublishMissingKubectlMessage,
                        title: Resources.GcloudMissingComponentTitle);
                }
                return(false);
            }

            return(true);
        }
Example #2
0
        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();
            }
        }