private async Task ConfigureDeployment(Recommendation recommendation, OptionSettingItem setting)
        {
            _toolInteractiveService.WriteLine(string.Empty);
            _toolInteractiveService.WriteLine($"{setting.Name}:");
            _toolInteractiveService.WriteLine($"{setting.Description}");

            var    currentValue = recommendation.GetOptionSettingValue(setting);
            object settingValue = null;

            if (setting.AllowedValues?.Count > 0)
            {
                var userInputConfig = new UserInputConfiguration <string>
                {
                    DisplaySelector = x => setting.ValueMapping[x],
                    DefaultSelector = x => x.Equals(currentValue),
                    CreateNew       = false
                };

                var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(setting.AllowedValues, string.Empty, userInputConfig);
                settingValue = userResponse.SelectedOption;

                // If they didn't change the value then don't store so we can rely on using the default in the recipe.
                if (Equals(settingValue, currentValue))
                {
                    return;
                }
            }
            else
            {
                if (setting.TypeHint.HasValue && _typeHintCommandFactory.GetCommand(setting.TypeHint.Value) is var typeHintCommand && typeHintCommand != null)
                {
                    settingValue = await typeHintCommand.Execute(recommendation, setting);
                }
Пример #2
0
        public async Task <object> Execute(Recommendation recommendation, OptionSettingItem optionSetting)
        {
            var currentValue = recommendation.GetOptionSettingValue(optionSetting);
            var keyPairs     = await _awsResourceQueryer.ListOfEC2KeyPairs();

            var userInputConfiguration = new UserInputConfiguration <KeyPairInfo>(
                kp => kp.KeyName,
                kp => kp.KeyName.Equals(currentValue)
                )
            {
                AskNewName   = true,
                EmptyOption  = true,
                CurrentValue = currentValue
            };

            var settingValue = "";

            while (true)
            {
                var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(keyPairs, "Select key pair to use:", userInputConfiguration);

                if (userResponse.IsEmpty)
                {
                    settingValue = "";
                    break;
                }
                else
                {
                    settingValue = userResponse.SelectedOption?.KeyName ?? userResponse.NewName ??
                                   throw new UserPromptForNameReturnedNullException("The user prompt for a new EC2 Key Pair name was null or empty.");
                }

                if (userResponse.CreateNew && !string.IsNullOrEmpty(userResponse.NewName))
                {
                    _toolInteractiveService.WriteLine(string.Empty);
                    _toolInteractiveService.WriteLine("You have chosen to create a new key pair.");
                    _toolInteractiveService.WriteLine("You are required to specify a directory to save the key pair private key.");

                    var answer = _consoleUtilities.AskYesNoQuestion("Do you want to continue?", "false");
                    if (answer == YesNo.No)
                    {
                        continue;
                    }

                    _toolInteractiveService.WriteLine(string.Empty);
                    _toolInteractiveService.WriteLine($"A new key pair will be created with the name {settingValue}.");

                    var keyPairDirectory = _consoleUtilities.AskForEC2KeyPairSaveDirectory(recommendation.ProjectPath);

                    await _awsResourceQueryer.CreateEC2KeyPair(settingValue, keyPairDirectory);
                }

                break;
            }

            return(settingValue ?? "");
        }
        public async Task <object> Execute(Recommendation recommendation, OptionSettingItem optionSetting)
        {
            var currentValue = recommendation.GetOptionSettingValue(optionSetting);
            var platformArns = await _awsResourceQueryer.GetElasticBeanstalkPlatformArns(_session);

            var userInputConfiguration = new UserInputConfiguration <PlatformSummary>
            {
                DisplaySelector = platform => $"{platform.PlatformBranchName} v{platform.PlatformVersion}",
                DefaultSelector = platform => platform.PlatformArn.Equals(currentValue),
                CreateNew       = false
            };

            var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(platformArns, "Select the Platform to use:", userInputConfiguration);

            return(userResponse.SelectedOption?.PlatformArn);
        }
Пример #4
0
        public async Task <object> Execute(Recommendation recommendation, OptionSettingItem optionSetting)
        {
            var loadBalancers = await _awsResourceQueryer.ListOfLoadBalancers(LoadBalancerTypeEnum.Application);

            var currentValue = recommendation.GetOptionSettingValue <string>(optionSetting);

            var userInputConfiguration = new UserInputConfiguration <LoadBalancer>(
                loadBalancer => loadBalancer.LoadBalancerName,
                loadBalancer => loadBalancer.LoadBalancerArn.Equals(currentValue))
            {
                AskNewName = false
            };

            var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(loadBalancers, "Select Load Balancer to deploy to:", userInputConfiguration);

            return(userResponse.SelectedOption?.LoadBalancerArn ?? string.Empty);
        }
Пример #5
0
        public async Task <object> Execute(Recommendation recommendation, OptionSettingItem optionSetting)
        {
            var typeHintData  = optionSetting.GetTypeHintData <IAMRoleTypeHintData>();
            var existingRoles = await _awsResourceQueryer.ListOfIAMRoles(typeHintData?.ServicePrincipal);

            var currentTypeHintResponse = recommendation.GetOptionSettingValue <IAMRoleTypeHintResponse>(optionSetting);

            var userInputConfiguration = new UserInputConfiguration <Role>(
                role => role.RoleName,
                role => currentTypeHintResponse.RoleArn?.Equals(role.Arn) ?? false);

            var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(existingRoles, "Select an IAM role", userInputConfiguration);

            return(new IAMRoleTypeHintResponse
            {
                CreateNew = userResponse.CreateNew,
                RoleArn = userResponse.SelectedOption?.Arn
            });
        }
        public async Task <object> Execute(Recommendation recommendation, OptionSettingItem optionSetting)
        {
            var currentVpcTypeHintResponse = optionSetting.GetTypeHintData <VpcTypeHintResponse>();

            var vpcs = await _awsResourceQueryer.GetListOfVpcs(_session);

            var userInputConfig = new UserInputConfiguration <Vpc>
            {
                DisplaySelector = vpc =>
                {
                    var name     = vpc.Tags?.FirstOrDefault(x => x.Key == "Name")?.Value ?? string.Empty;
                    var namePart =
                        string.IsNullOrEmpty(name)
                            ? ""
                            : $" ({name}) ";

                    var isDefaultPart =
                        vpc.IsDefault
                            ? " *** Account Default VPC ***"
                            : "";

                    return($"{vpc.VpcId}{namePart}{isDefaultPart}");
                },
                DefaultSelector = vpc =>
                                  !string.IsNullOrEmpty(currentVpcTypeHintResponse?.VpcId)
                        ? vpc.VpcId == currentVpcTypeHintResponse.VpcId
                        : vpc.IsDefault
            };

            var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(
                vpcs,
                "Select a VPC",
                userInputConfig);

            return(new VpcTypeHintResponse
            {
                IsDefault = userResponse.SelectedOption?.IsDefault == true,
                CreateNew = userResponse.CreateNew,
                VpcId = userResponse.SelectedOption?.VpcId ?? ""
            });
        }
        public async Task <object> Execute(Recommendation recommendation, OptionSettingItem optionSetting)
        {
            var clusters = await _awsResourceQueryer.ListOfECSClusters();

            var currentTypeHintResponse = recommendation.GetOptionSettingValue <ECSClusterTypeHintResponse>(optionSetting);

            var userInputConfiguration = new UserInputConfiguration <Cluster>(
                cluster => cluster.ClusterName,
                cluster => cluster.ClusterArn.Equals(currentTypeHintResponse?.ClusterArn),
                currentTypeHintResponse.NewClusterName)
            {
                AskNewName = true
            };

            var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(clusters, "Select ECS cluster to deploy to:", userInputConfiguration);

            return(new ECSClusterTypeHintResponse(
                       userResponse.CreateNew,
                       userResponse.SelectedOption?.ClusterArn ?? string.Empty,
                       userResponse.NewName ?? string.Empty));
        }
        public async Task <object> Execute(Recommendation recommendation, OptionSettingItem optionSetting)
        {
            var applications = await _awsResourceQueryer.ListOfElasticBeanstalkApplications(_session);

            var currentTypeHintResponse = recommendation.GetOptionSettingValue <BeanstalkApplicationTypeHintResponse>(optionSetting);

            var userInputConfiguration = new UserInputConfiguration <ApplicationDescription>
            {
                DisplaySelector = app => app.ApplicationName,
                DefaultSelector = app => app.ApplicationName.Equals(currentTypeHintResponse?.ApplicationName),
                AskNewName      = true,
                DefaultNewName  = currentTypeHintResponse.ApplicationName
            };

            var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(applications, "Select Elastic Beanstalk application to deploy to:", userInputConfiguration);

            return(new BeanstalkApplicationTypeHintResponse
            {
                CreateNew = userResponse.CreateNew,
                ApplicationName = userResponse.SelectedOption?.ApplicationName ?? userResponse.NewName
            });
        }
        public async Task <object> Execute(Recommendation recommendation, OptionSettingItem optionSetting)
        {
            var applications = await _awsResourceQueryer.ListOfElasticBeanstalkApplications();

            var currentTypeHintResponse = recommendation.GetOptionSettingValue <BeanstalkApplicationTypeHintResponse>(optionSetting);

            var userInputConfiguration = new UserInputConfiguration <ApplicationDescription>(
                app => app.ApplicationName,
                app => app.ApplicationName.Equals(currentTypeHintResponse?.ApplicationName),
                currentTypeHintResponse.ApplicationName)
            {
                AskNewName = true,
            };

            var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(applications, "Select Elastic Beanstalk application to deploy to:", userInputConfiguration);

            return(new BeanstalkApplicationTypeHintResponse(
                       userResponse.CreateNew,
                       userResponse.SelectedOption?.ApplicationName ?? userResponse.NewName
                       ?? throw new UserPromptForNameReturnedNullException("The user response for a new application name was null.")
                       ));
        }