/// <summary>
        /// Verify that the Cloud SDK is installed and at the right version. Optionally also verify that the given
        /// component is installed.
        /// </summary>
        /// <param name="component">The component to check, optional.</param>
        /// <returns>True if the Cloud SDK installation is valid.</returns>
        public static async Task <bool> VerifyGCloudDependencies(GCloudComponent component = GCloudComponent.None)
        {
            var result = await GCloudWrapper.ValidateGCloudAsync(component);

            if (result.IsValid)
            {
                return(true);
            }

            if (!result.IsCloudSdkInstalled)
            {
                LinkPromptDialogWindow.PromptUser(
                    Resources.GcloudMissingGcloudErrorTitle,
                    Resources.GcloudMissingCloudSdkErrorMessage,
                    new LinkInfo(link: "https://cloud.google.com/sdk/", caption: Resources.GcloudInstallLinkCaption));
            }
            else if (!result.IsCloudSdkUpdated)
            {
                UserPromptUtils.ErrorPrompt(
                    message: String.Format(
                        Resources.GCloudWrapperUtilsOldCloudSdkMessage,
                        result.CloudSdkVersion,
                        GCloudWrapper.GCloudSdkMinimumVersion),
                    title: Resources.GCloudWrapperUtilsOldCloudSdkTitle);
            }
            else
            {
                UserPromptUtils.ErrorPrompt(
                    message: String.Format(Resources.GcloudMissingComponentErrorMessage, component),
                    title: Resources.GcloudMissingComponentTitle);
            }

            return(false);
        }
        /// <summary>
        /// Verify that the Cloud SDK is installed and at the right version. Optionally also verify that the given
        /// component is installed.
        /// </summary>
        /// <param name="component">The component to check, optional.</param>
        /// <returns>True if the Cloud SDK installation is valid.</returns>
        public static async Task <bool> VerifyGCloudDependenciesAsync(GCloudComponent component = GCloudComponent.None)
        {
            GCloudValidationResult result = await GCloudWrapper.ValidateGCloudAsync(component);

            if (result.IsValid)
            {
                return(true);
            }

            if (!result.IsCloudSdkInstalled)
            {
                LinkPromptDialogWindow.PromptUser(
                    Resources.GcloudMissingGcloudErrorTitle,
                    Resources.GcloudMissingCloudSdkErrorMessage,
                    new LinkInfo(link: "https://cloud.google.com/sdk/", caption: Resources.GcloudInstallLinkCaption));
            }
            else if (result.IsObsolete)
            {
                UserPromptService.Default.ErrorPrompt(
                    message: string.Format(
                        Resources.GCloudWrapperUtilsOldCloudSdkMessage,
                        result.CloudSdkVersion,
                        GCloud.GCloudWrapper.GCloudSdkMinimumVersion),
                    title: Resources.GCloudWrapperUtilsOldCloudSdkTitle);
            }
            else
            {
                ShowCopyablePrompt(
                    Resources.GcloudMissingComponentTitle,
                    string.Format(Resources.GcloudMissingComponentErrorMessage, component),
                    string.Format(Resources.GcloudMissingComponentInstallCommand, component.ToString().ToLower()));
            }

            return(false);
        }
Beispiel #3
0
 /// <summary>
 /// Asking to install Git for Windows if git.exe is not found
 /// </summary>
 /// <returns>
 /// True: It is installed properly.
 /// Otherwise, returns false.
 /// </returns>
 public static bool ValidateGitForWindowsInstalled()
 {
     if (String.IsNullOrWhiteSpace(GitRepository.GetGitPath()))
     {
         LinkPromptDialogWindow.PromptUser(
             Resources.GitUtilsMissingGitErrorTitle,
             Resources.GitUtilsMissingGitErrorMessage,
             new LinkInfo(link: GitInstallationLink, caption: Resources.GitUtilsGitInstallLinkCaption));
         return(false);
     }
     return(true);
 }
Beispiel #4
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);
        }
Beispiel #5
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();
            }
        }