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; } }
protected override void BeforeEach() { _processServiceMock = new Mock <IProcessService>(); SetupRunCommandResult(true); PackageMock.Setup(p => p.ProcessService).Returns(_processServiceMock.Object); _objectUnderTest = new GCloudContext(); _mockedOutputAction = Mock.Of <Action <string> >(); }
public DeploymentOptions(string service, string version, bool promote, bool openWebsite, string configuration) { Service = service; Version = version ?? GcpPublishStepsUtils.GetDefaultVersion(); Promote = promote; OpenWebsite = openWebsite; Configuration = configuration; Context = new GCloudContext(); }
public void BeforeEach() { _processServiceMock = new Mock <IProcessService>(); _versionResultSource = new TaskCompletionSource <CloudSdkVersions>(); SetupGetJsonOutput("version", _versionResultSource.Task); PackageMock.Setup(p => p.ProcessService).Returns(_processServiceMock.Object); _objectUnderTest = new GCloudContext(); _mockedOutputAction = Mock.Of <Func <string, Task> >(); }
public void TestConstructor_SetsProjectId() { const string expectedProjectId = "expected-project-id"; PackageMock.SetupGet(p => p.CredentialsStore.CurrentProjectId).Returns(expectedProjectId); var objectUnderTest = new GCloudContext(); Assert.AreEqual(expectedProjectId, objectUnderTest.ProjectId); }
public void TestConstructor_SetsCredentialsPath() { const string expectedCredentialsPath = "expected-credentials-path"; PackageMock.SetupGet(p => p.CredentialsStore.CurrentAccountPath) .Returns(expectedCredentialsPath); var objectUnderTest = new GCloudContext(); Assert.AreEqual(expectedCredentialsPath, objectUnderTest.CredentialsPath); }
private Task <bool> DeployAppBundleAsync( string stageDirectory, string version, bool promote, GCloudContext context, Action <string> outputAction) { string appYamlPath = Path.Combine(stageDirectory, AppEngineConfiguration.AppYamlName); return(context.DeployAppAsync(appYamlPath, version, promote, outputAction)); }
private static Task <bool> DeployAppBundleAsync( string stageDirectory, string version, bool promote, GCloudContext context, Action <string> outputAction) { var appYamlPath = Path.Combine(stageDirectory, AppYamlName); return(GCloudWrapper.DeployAppAsync( appYaml: appYamlPath, version: version, promote: promote, outputAction: outputAction, context: context)); }
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); } }
public override async void Publish() { if (!ValidateInput()) { Debug.WriteLine("Invalid input cancelled the operation."); return; } var project = _publishDialog.Project; try { 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(); AppEngineFlexDeploymentResult result; using (var frozen = StatusbarHelper.Freeze()) using (var animationShown = StatusbarHelper.ShowDeployAnimation()) using (var progress = StatusbarHelper.ShowProgressBar(Resources.FlexPublishProgressMessage)) using (var deployingOperation = ShellUtils.SetShellUIBusy()) { result = await AppEngineFlexDeployment.PublishProjectAsync( project.FullPath, options, progress, GcpOutputWindow.OutputLine); } 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); } } else { GcpOutputWindow.OutputLine(String.Format(Resources.FlexPublishFailedMessage, project.Name)); StatusbarHelper.SetText(Resources.PublishFailureStatusMessage); } } catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex)) { GcpOutputWindow.OutputLine(String.Format(Resources.FlexPublishFailedMessage, project.Name)); StatusbarHelper.SetText(Resources.PublishFailureStatusMessage); } }
/// <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 { var verifyGCloudTask = VerifyGCloudDependencies(); _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, 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(); GkeDeploymentResult result; using (var frozen = StatusbarHelper.Freeze()) using (var animationShown = StatusbarHelper.ShowDeployAnimation()) using (var progress = StatusbarHelper.ShowProgressBar(Resources.GkePublishDeploymentStatusMessage)) using (var deployingOperation = ShellUtils.SetShellUIBusy()) { result = await GkeDeployment.PublishProjectAsync( project.FullPath, options, progress, GcpOutputWindow.OutputLine); } if (result != null) { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentSuccessMessage, project.Name)); if (result.DeploymentUpdated) { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentUpdatedMessage, options.DeploymentName)); } if (result.DeploymentScaled) { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentScaledMessage, options.DeploymentName, options.Replicas)); } if (result.WasExposed) { if (result.ServiceIpAddress != null) { GcpOutputWindow.OutputLine( String.Format(Resources.GkePublishServiceIpMessage, DeploymentName, result.ServiceIpAddress)); } else { GcpOutputWindow.OutputLine(Resources.GkePublishServiceIpTimeoutMessage); } } StatusbarHelper.SetText(Resources.PublishSuccessStatusMessage); if (OpenWebsite && result.WasExposed && result.ServiceIpAddress != null) { Process.Start($"http://{result.ServiceIpAddress}"); } } else { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentFailureMessage, project.Name)); StatusbarHelper.SetText(Resources.PublishFailureStatusMessage); } } } catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex)) { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentFailureMessage, project.Name)); StatusbarHelper.SetText(Resources.PublishFailureStatusMessage); _publishDialog.FinishFlow(); } }
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)); } }