private async Task<WindowsInstanceCredentials> CreateOrResetCredentials(string user) { try { Debug.WriteLine("The user requested the password to be generated."); if (!UserPromptUtils.Default.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}"); if (!await GCloudWrapperUtils.VerifyGCloudDependencies()) { Debug.WriteLine("Gcloud dependencies not met, aborting change of password."); return null; } var context = new GCloudContext(); return await context.ResetWindowsCredentialsAsync(_instance.Name, _instance.GetZoneName(), user); } catch (GCloudException ex) { UserPromptUtils.Default.ErrorPrompt( message: String.Format(Resources.ResetPasswordFailedPromptMessage, _instance.Name), title: Resources.ResetPasswordConfirmationPromptTitle, errorDetails: ex.Message); return null; } }
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 GCloudWrapperUtils.VerifyGCloudDependencies("beta")) { 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); } }
public async Task TestMissingComponentPrompt() { _validateGCloudAsyncSource.SetResult(GCloudValidationResult.MissingComponent); _showCopyablePromptMock .Setup(a => a(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Callback <string, string, string>((title, message, copyableMessage) => { Assert.AreEqual(s_missingComponentTitle, title); Assert.AreEqual(s_missingComponentMessage, message); Assert.AreEqual(s_missingComponentInstallCommand, copyableMessage, false); }); await GCloudWrapperUtils.VerifyGCloudDependencies(GCloudComponent.Kubectl); _showCopyablePromptMock.Verify(a => a(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }
public override async void Publish() { if (!ValidateInput()) { Debug.WriteLine("Invalid input cancelled the operation."); return; } var project = _publishDialog.Project; try { var verifyGcloudTask = GCloudWrapperUtils.VerifyGCloudDependencies("beta"); _publishDialog.TrackTask(verifyGcloudTask); if (!await verifyGcloudTask) { Debug.WriteLine("Gcloud dependencies not met, aborting publish operation."); return; } ShellUtils.SaveAllFiles(); var context = new GCloudContext { CredentialsPath = CredentialsStore.Default.CurrentAccountPath, ProjectId = CredentialsStore.Default.CurrentProjectId, AppName = GoogleCloudExtensionPackage.ApplicationName, AppVersion = GoogleCloudExtensionPackage.ApplicationVersion, }; var options = new AppEngineFlexDeployment.DeploymentOptions { Version = Version, Promote = Promote, Context = context }; GcpOutputWindow.Activate(); GcpOutputWindow.Clear(); GcpOutputWindow.OutputLine(String.Format(Resources.GcePublishStepStartMessage, project.Name)); _publishDialog.FinishFlow(); TimeSpan deploymentDuration; AppEngineFlexDeploymentResult result; using (StatusbarHelper.Freeze()) using (StatusbarHelper.ShowDeployAnimation()) using (var progress = StatusbarHelper.ShowProgressBar(Resources.FlexPublishProgressMessage)) using (ShellUtils.SetShellUIBusy()) { var startDeploymentTime = DateTime.Now; result = await AppEngineFlexDeployment.PublishProjectAsync( project, options, progress, VsVersionUtils.ToolsPathProvider, GcpOutputWindow.OutputLine); deploymentDuration = DateTime.Now - startDeploymentTime; } if (result != null) { GcpOutputWindow.OutputLine(String.Format(Resources.FlexPublishSuccessMessage, project.Name)); StatusbarHelper.SetText(Resources.PublishSuccessStatusMessage); var url = result.GetDeploymentUrl(); GcpOutputWindow.OutputLine(String.Format(Resources.PublishUrlMessage, url)); if (OpenWebsite) { Process.Start(url); } EventsReporterWrapper.ReportEvent(GaeDeployedEvent.Create(CommandStatus.Success, deploymentDuration)); } else { GcpOutputWindow.OutputLine(String.Format(Resources.FlexPublishFailedMessage, project.Name)); StatusbarHelper.SetText(Resources.PublishFailureStatusMessage); EventsReporterWrapper.ReportEvent(GaeDeployedEvent.Create(CommandStatus.Failure)); } } catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex)) { GcpOutputWindow.OutputLine(String.Format(Resources.FlexPublishFailedMessage, project.Name)); StatusbarHelper.SetText(Resources.PublishFailureStatusMessage); EventsReporterWrapper.ReportEvent(GaeDeployedEvent.Create(CommandStatus.Failure)); } }
/// <summary> /// Start the publish operation. /// </summary> public override async void Publish() { if (!ValidateInput()) { Debug.WriteLine("Invalid input cancelled the operation."); return; } var project = _publishDialog.Project; try { ShellUtils.SaveAllFiles(); var verifyGCloudTask = GCloudWrapperUtils.VerifyGCloudDependencies("kubectl"); _publishDialog.TrackTask(verifyGCloudTask); if (!await verifyGCloudTask) { Debug.WriteLine("Aborting deployment, no kubectl was found."); return; } var gcloudContext = new GCloudContext { CredentialsPath = CredentialsStore.Default.CurrentAccountPath, ProjectId = CredentialsStore.Default.CurrentProjectId, AppName = GoogleCloudExtensionPackage.ApplicationName, AppVersion = GoogleCloudExtensionPackage.ApplicationVersion, }; var kubectlContextTask = GCloudWrapper.GetKubectlContextForClusterAsync( cluster: SelectedCluster.Name, zone: SelectedCluster.Zone, context: gcloudContext); _publishDialog.TrackTask(kubectlContextTask); using (var kubectlContext = await kubectlContextTask) { var deploymentExistsTask = KubectlWrapper.DeploymentExistsAsync(DeploymentName, kubectlContext); _publishDialog.TrackTask(deploymentExistsTask); if (await deploymentExistsTask) { if (!UserPromptUtils.ActionPrompt( String.Format(Resources.GkePublishDeploymentAlreadyExistsMessage, DeploymentName), Resources.GkePublishDeploymentAlreadyExistsTitle, actionCaption: Resources.UiUpdateButtonCaption)) { return; } } var options = new GkeDeployment.DeploymentOptions { Cluster = SelectedCluster.Name, Zone = SelectedCluster.Zone, DeploymentName = DeploymentName, DeploymentVersion = DeploymentVersion, ExposeService = ExposeService, ExposePublicService = ExposePublicService, GCloudContext = gcloudContext, KubectlContext = kubectlContext, Replicas = int.Parse(Replicas), WaitingForServiceIpCallback = () => GcpOutputWindow.OutputLine(Resources.GkePublishWaitingForServiceIpMessage) }; GcpOutputWindow.Activate(); GcpOutputWindow.Clear(); GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeployingToGkeMessage, project.Name)); _publishDialog.FinishFlow(); TimeSpan deploymentDuration; GkeDeploymentResult result; using (StatusbarHelper.Freeze()) using (StatusbarHelper.ShowDeployAnimation()) using (var progress = StatusbarHelper.ShowProgressBar(Resources.GkePublishDeploymentStatusMessage)) using (ShellUtils.SetShellUIBusy()) { var deploymentStartTime = DateTime.Now; result = await GkeDeployment.PublishProjectAsync( project, options, progress, VsVersionUtils.ToolsPathProvider, GcpOutputWindow.OutputLine); deploymentDuration = DateTime.Now - deploymentStartTime; } if (result != null) { OutputResultData(result, options); StatusbarHelper.SetText(Resources.PublishSuccessStatusMessage); if (OpenWebsite && result.ServiceExposed && result.PublicServiceIpAddress != null) { Process.Start($"http://{result.PublicServiceIpAddress}"); } EventsReporterWrapper.ReportEvent(GkeDeployedEvent.Create(CommandStatus.Success, deploymentDuration)); } else { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentFailureMessage, project.Name)); StatusbarHelper.SetText(Resources.PublishFailureStatusMessage); EventsReporterWrapper.ReportEvent(GkeDeployedEvent.Create(CommandStatus.Failure)); } } } catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex)) { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentFailureMessage, project.Name)); StatusbarHelper.SetText(Resources.PublishFailureStatusMessage); _publishDialog.FinishFlow(); EventsReporterWrapper.ReportEvent(GkeDeployedEvent.Create(CommandStatus.Failure)); } }