/// <summary> /// This method is responsible for selecting a deployment recommendation. /// </summary> /// <param name="userDeploymentSettings">The deserialized object from the user provided config file.<see cref="UserDeploymentSettings"/></param> /// <param name="recommendations">A List of available recommendations to choose from.</param> /// <returns><see cref="Recommendation"/></returns> private Recommendation GetSelectedRecommendation(UserDeploymentSettings?userDeploymentSettings, List <Recommendation> recommendations) { var deploymentSettingsRecipeId = userDeploymentSettings?.RecipeId; if (string.IsNullOrEmpty(deploymentSettingsRecipeId)) { if (_toolInteractiveService.DisableInteractive) { var message = "The \"--silent\" CLI argument can only be used if a deployment recipe is specified as part of the " + "deployement-settings file or if a path to a custom CDK deployment project is provided via the '--deployment-project' CLI argument." + $"{Environment.NewLine}Please provide a deployment recipe and try again"; throw new InvalidCliArgumentException(message); } return(_consoleUtilities.AskToChooseRecommendation(recommendations)); } var selectedRecommendation = recommendations.FirstOrDefault(x => x.Recipe.Id.Equals(deploymentSettingsRecipeId, StringComparison.Ordinal)); if (selectedRecommendation == null) { throw new InvalidUserDeploymentSettingsException($"The user deployment settings provided contains an invalid value for the property '{nameof(userDeploymentSettings.RecipeId)}'."); } _toolInteractiveService.WriteLine(); _toolInteractiveService.WriteLine($"Configuring Recommendation with: '{selectedRecommendation.Name}'."); return(selectedRecommendation); }
/// <summary> /// This method takes a user specified directory path and generates the CDK deployment project at this location. /// If the provided directory path is an empty string, then a default directory is created to save the CDK deployment project. /// </summary> /// <param name="saveCdkDirectoryPath">An absolute or a relative path provided by the user.</param> /// <param name="projectDisplayName">The name of the deployment project that will be displayed in the list of available deployment options.</param> /// <returns></returns> public async Task ExecuteAsync(string saveCdkDirectoryPath, string projectDisplayName) { var orchestrator = new Orchestrator(_session, new[] { RecipeLocator.FindRecipeDefinitionsPath() }); var recommendations = await GenerateRecommendationsToSaveDeploymentProject(orchestrator); var selectedRecommendation = _consoleUtilities.AskToChooseRecommendation(recommendations); if (string.IsNullOrEmpty(saveCdkDirectoryPath)) { saveCdkDirectoryPath = GenerateDefaultSaveDirectoryPath(); } var newDirectoryCreated = CreateSaveCdkDirectory(saveCdkDirectoryPath); var(isValid, errorMessage) = ValidateSaveCdkDirectory(saveCdkDirectoryPath); if (!isValid) { if (newDirectoryCreated) { _directoryManager.Delete(saveCdkDirectoryPath); } errorMessage = $"Failed to generate deployment project.{Environment.NewLine}{errorMessage}"; throw new InvalidSaveDirectoryForCdkProject(errorMessage.Trim()); } var directoryUnderSourceControl = await IsDirectoryUnderSourceControl(saveCdkDirectoryPath); if (!directoryUnderSourceControl) { var userPrompt = "Warning: The target directory is not being tracked by source control. If the saved deployment " + "project is used for deployment it is important that the deployment project is retained to allow " + "future redeployments to previously deployed applications. " + Environment.NewLine + Environment.NewLine + "Do you still want to continue?"; _toolInteractiveService.WriteLine(); var yesNoResult = _consoleUtilities.AskYesNoQuestion(userPrompt, YesNo.Yes); if (yesNoResult == YesNo.No) { if (newDirectoryCreated) { _directoryManager.Delete(saveCdkDirectoryPath); } return; } } _cdkProjectHandler.CreateCdkProject(selectedRecommendation, _session, saveCdkDirectoryPath); await GenerateDeploymentRecipeSnapShot(selectedRecommendation, saveCdkDirectoryPath, projectDisplayName); var saveCdkDirectoryFullPath = _directoryManager.GetDirectoryInfo(saveCdkDirectoryPath).FullName; _toolInteractiveService.WriteLine(); _toolInteractiveService.WriteLine($"The CDK deployment project is saved at: {saveCdkDirectoryFullPath}"); await _deploymentManifestEngine.UpdateDeploymentManifestFile(saveCdkDirectoryFullPath, _targetApplicationFullPath); }