public async Task<List<KeyPairInfo>> ListOfEC2KeyPairs(OrchestratorSession session)
        {
            var ec2Client = _awsClientFactory.GetAWSClient<IAmazonEC2>(session.AWSCredentials, session.AWSRegion);
            var response = await ec2Client.DescribeKeyPairsAsync();

            return response.KeyPairs;
        }
示例#2
0
 public IAMRoleCommand(IToolInteractiveService toolInteractiveService, IAWSResourceQueryer awsResourceQueryer, OrchestratorSession session, ConsoleUtilities consoleUtilities)
 {
     _toolInteractiveService = toolInteractiveService;
     _awsResourceQueryer     = awsResourceQueryer;
     _session          = session;
     _consoleUtilities = consoleUtilities;
 }
        public async Task<List<PlatformSummary>> GetElasticBeanstalkPlatformArns(OrchestratorSession session)
        {
            var beanstalkClient = _awsClientFactory.GetAWSClient<IAmazonElasticBeanstalk>(session.AWSCredentials, session.AWSRegion);

            var request = new ListPlatformVersionsRequest
            {
                Filters = new List<PlatformFilter>
                {
                    new PlatformFilter
                    {
                        Operator = "=",
                        Type = "PlatformStatus",
                        Values = { "Ready" }
                    }
                }
            };
            var response = await beanstalkClient.ListPlatformVersionsAsync(request);

            var platformVersions = new List<PlatformSummary>();
            foreach (var version in response.PlatformSummaryList)
            {
                if (string.IsNullOrEmpty(version.PlatformCategory) || string.IsNullOrEmpty(version.PlatformBranchLifecycleState))
                    continue;

                if (!version.PlatformBranchLifecycleState.Equals("Supported"))
                    continue;

                if (!version.PlatformCategory.Equals(".NET Core"))
                    continue;

                platformVersions.Add(version);
            }

            return platformVersions;
        }
        public RecommendationEngine(IEnumerable <string> recipeDefinitionPaths, OrchestratorSession orchestratorSession)
        {
            _orchestratorSession = orchestratorSession;

            recipeDefinitionPaths ??= new List <string>();

            var uniqueRecipeId = new HashSet <string>();

            foreach (var recommendationPath in recipeDefinitionPaths)
            {
                foreach (var recipeFile in Directory.GetFiles(recommendationPath, "*.recipe", SearchOption.TopDirectoryOnly))
                {
                    try
                    {
                        var content    = File.ReadAllText(recipeFile);
                        var definition = JsonConvert.DeserializeObject <RecipeDefinition>(content);
                        definition.RecipePath = recipeFile;
                        if (!uniqueRecipeId.Contains(definition.Id))
                        {
                            _availableRecommendations.Add(definition);
                            uniqueRecipeId.Add(definition.Id);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception($"Failed to Deserialize Recipe [{recipeFile}]: {e.Message}", e);
                    }
                }
            }
        }
 public DotnetBeanstalkPlatformArnCommand(IToolInteractiveService toolInteractiveService, IAWSResourceQueryer awsResourceQueryer, OrchestratorSession session, ConsoleUtilities consoleUtilities)
 {
     _toolInteractiveService = toolInteractiveService;
     _awsResourceQueryer     = awsResourceQueryer;
     _session          = session;
     _consoleUtilities = consoleUtilities;
 }
        private async Task <Orchestrator> GetOrchestrator(string targetApplicationProjectPath)
        {
            var directoryManager              = new DirectoryManager();
            var fileManager                   = new FileManager();
            var deploymentManifestEngine      = new DeploymentManifestEngine(directoryManager, fileManager);
            var localUserSettingsEngine       = new LocalUserSettingsEngine(fileManager, directoryManager);
            var consoleInteractiveServiceImpl = new ConsoleInteractiveServiceImpl();
            var consoleOrchestratorLogger     = new ConsoleOrchestratorLogger(consoleInteractiveServiceImpl);
            var commandLineWrapper            = new CommandLineWrapper(consoleOrchestratorLogger);
            var customRecipeLocator           = new CustomRecipeLocator(deploymentManifestEngine, consoleOrchestratorLogger, commandLineWrapper, directoryManager);

            var projectDefinition = await new ProjectDefinitionParser(fileManager, directoryManager).Parse(targetApplicationProjectPath);
            var session           = new OrchestratorSession(projectDefinition);

            return(new Orchestrator(session,
                                    consoleOrchestratorLogger,
                                    new Mock <ICdkProjectHandler>().Object,
                                    new Mock <ICDKManager>().Object,
                                    new Mock <ICDKVersionDetector>().Object,
                                    new TestToolAWSResourceQueryer(),
                                    new Mock <IDeploymentBundleHandler>().Object,
                                    localUserSettingsEngine,
                                    new Mock <IDockerEngine>().Object,
                                    customRecipeLocator,
                                    new List <string> {
                RecipeLocator.FindRecipeDefinitionsPath()
            },
                                    directoryManager));
        }
示例#7
0
 public DeleteDeploymentCommand(IAWSClientFactory awsClientFactory, IToolInteractiveService interactiveService, OrchestratorSession session)
 {
     _awsClientFactory     = awsClientFactory;
     _interactiveService   = interactiveService;
     _session              = session;
     _cloudFormationClient = _awsClientFactory.GetAWSClient <IAmazonCloudFormation>(_session.AWSCredentials, _session.AWSRegion);
     _consoleUtilities     = new ConsoleUtilities(interactiveService);
 }
        public async Task<List<AuthorizationData>> GetECRAuthorizationToken(OrchestratorSession session)
        {
            var ecrClient = _awsClientFactory.GetAWSClient<IAmazonECR>(session.AWSCredentials, session.AWSRegion);

            var response = await ecrClient.GetAuthorizationTokenAsync(new GetAuthorizationTokenRequest());

            return response.AuthorizationData;
        }
示例#9
0
 public RecommendationTestInput(
     RuleTest test,
     ProjectDefinition projectDefinition,
     OrchestratorSession session)
 {
     Test = test;
     ProjectDefinition = projectDefinition;
     Session           = session;
 }
示例#10
0
        public DeploymentBundleHandlerTests()
        {
            _session = new OrchestratorSession();
            var awsResourceQueryer = new TestToolAWSResourceQueryer();
            var interactiveService = new TestToolOrchestratorInteractiveService();

            _commandLineWrapper      = new TestToolCommandLineWrapper();
            _directoryManager        = new TestDirectoryManager();
            _zipFileManager          = new TestZipFileManager();
            _deploymentBundleHandler = new DeploymentBundleHandler(_session, _commandLineWrapper, awsResourceQueryer, interactiveService, _directoryManager, _zipFileManager);
        }
        public async Task<PlatformSummary> GetLatestElasticBeanstalkPlatformArn(OrchestratorSession session)
        {
            var platforms = await GetElasticBeanstalkPlatformArns(session);

            if (!platforms.Any())
            {
                throw new AmazonElasticBeanstalkException(".NET Core Solution Stack doesn't exist.");
            }

            return platforms.First();
        }
        public async Task<List<Vpc>> GetListOfVpcs(OrchestratorSession session)
        {
            var vpcClient = _awsClientFactory.GetAWSClient<IAmazonEC2>(session.AWSCredentials, session.AWSRegion);

            return await vpcClient.Paginators
                .DescribeVpcs(new DescribeVpcsRequest())
                .Vpcs
                .OrderByDescending(x => x.IsDefault)
                .ThenBy(x => x.VpcId)
                .ToListAsync();
        }
        public async Task<string> CreateEC2KeyPair(OrchestratorSession session, string keyName, string saveLocation)
        {
            var ec2Client = _awsClientFactory.GetAWSClient<IAmazonEC2>(session.AWSCredentials, session.AWSRegion);

            var request = new CreateKeyPairRequest() { KeyName = keyName };

            var response = await ec2Client.CreateKeyPairAsync(request);

            File.WriteAllText(Path.Combine(saveLocation, $"{keyName}.pem"), response.KeyPair.KeyMaterial);

            return response.KeyPair.KeyName;
        }
        public async Task<Repository> CreateECRRepository(OrchestratorSession session, string repositoryName)
        {
            var ecrClient = _awsClientFactory.GetAWSClient<IAmazonECR>(session.AWSCredentials, session.AWSRegion);

            var request = new CreateRepositoryRequest
            {
                RepositoryName = repositoryName
            };

            var response = await ecrClient.CreateRepositoryAsync(request);

            return response.Repository;
        }
示例#15
0
 public ListDeploymentsCommand(IToolInteractiveService interactiveService,
                               IOrchestratorInteractiveService orchestratorInteractiveService,
                               ICdkProjectHandler cdkProjectHandler,
                               IDeploymentBundleHandler deploymentBundleHandler,
                               IAWSResourceQueryer awsResourceQueryer,
                               OrchestratorSession session)
 {
     _interactiveService             = interactiveService;
     _orchestratorInteractiveService = orchestratorInteractiveService;
     _cdkProjectHandler       = cdkProjectHandler;
     _deploymentBundleHandler = deploymentBundleHandler;
     _awsResourceQueryer      = awsResourceQueryer;
     _session = session;
 }
        public Task <List <AuthorizationData> > GetECRAuthorizationToken(OrchestratorSession session)
        {
            var authorizationData = new AuthorizationData
            {
                //  Test authorization token is encoded dummy 'username:password' string
                AuthorizationToken = "dXNlcm5hbWU6cGFzc3dvcmQ=",
                ProxyEndpoint      = "endpoint"
            };

            return(Task.FromResult <List <AuthorizationData> >(new List <AuthorizationData>()
            {
                authorizationData
            }));
        }
示例#17
0
        public void ShouldIncludeTests(RuleEffect effect, bool testPass, bool expectedResult)
        {
            var awsCredentials = new Mock <AWSCredentials>();
            var session        = new OrchestratorSession(
                null,
                awsCredentials.Object,
                "us-west-2",
                "123456789012")
            {
                AWSProfileName = "default"
            };
            var engine = new RecommendationEngine(new[] { RecipeLocator.FindRecipeDefinitionsPath() }, session);

            Assert.Equal(expectedResult, engine.ShouldInclude(effect, testPass));
        }
        public async Task<List<Cluster>> ListOfECSClusters(OrchestratorSession session)
        {
            var ecsClient = _awsClientFactory.GetAWSClient<IAmazonECS>(session.AWSCredentials, session.AWSRegion);

            var clusterArns = await ecsClient.Paginators
                .ListClusters(new ListClustersRequest())
                .ClusterArns
                .ToListAsync();

            var clusters = await ecsClient.DescribeClustersAsync(new DescribeClustersRequest
            {
                Clusters = clusterArns
            });

            return clusters.Clusters;
        }
        public async Task<List<Role>> ListOfIAMRoles(OrchestratorSession session, string servicePrincipal)
        {
            var identityManagementServiceClient = _awsClientFactory.GetAWSClient<IAmazonIdentityManagementService>(session.AWSCredentials, session.AWSRegion);

            var listRolesRequest = new ListRolesRequest();
            var roles = new List<Role>();

            var listStacksPaginator = identityManagementServiceClient.Paginators.ListRoles(listRolesRequest);
            await foreach (var response in listStacksPaginator.Responses)
            {
                var filteredRoles = response.Roles.Where(role => AssumeRoleServicePrincipalSelector(role, servicePrincipal));
                roles.AddRange(filteredRoles);
            }

            return roles;
        }
示例#20
0
        private async Task <RecommendationEngine> BuildRecommendationEngine(string testProjectName)
        {
            var fullPath = SystemIOUtilities.ResolvePath(testProjectName);

            var parser         = new ProjectDefinitionParser(new FileManager(), new DirectoryManager());
            var awsCredentials = new Mock <AWSCredentials>();
            var session        = new OrchestratorSession(
                await parser.Parse(fullPath),
                awsCredentials.Object,
                "us-west-2",
                "123456789012")
            {
                AWSProfileName = "default"
            };

            return(new RecommendationEngine(new[] { RecipeLocator.FindRecipeDefinitionsPath() }, session));
        }
 public DeployCommand(
     IToolInteractiveService toolInteractiveService,
     IOrchestratorInteractiveService orchestratorInteractiveService,
     ICdkProjectHandler cdkProjectHandler,
     IDeploymentBundleHandler deploymentBundleHandler,
     IAWSResourceQueryer awsResourceQueryer,
     OrchestratorSession session)
 {
     _toolInteractiveService         = toolInteractiveService;
     _orchestratorInteractiveService = orchestratorInteractiveService;
     _cdkProjectHandler       = cdkProjectHandler;
     _deploymentBundleHandler = deploymentBundleHandler;
     _awsResourceQueryer      = awsResourceQueryer;
     _consoleUtilities        = new ConsoleUtilities(toolInteractiveService);
     _session = session;
     _typeHintCommandFactory = new TypeHintCommandFactory(_toolInteractiveService, _awsResourceQueryer, _session, _consoleUtilities);
 }
        public Task <List <Repository> > GetECRRepositories(OrchestratorSession session, List <string> repositoryNames)
        {
            if (repositoryNames.Count == 0)
            {
                return(Task.FromResult <List <Repository> >(new List <Repository>()
                {
                }));
            }

            var repository = new Repository
            {
                RepositoryName = repositoryNames[0]
            };

            return(Task.FromResult <List <Repository> >(new List <Repository>()
            {
                repository
            }));
        }
示例#23
0
 public DeployCommand(
     IToolInteractiveService toolInteractiveService,
     IOrchestratorInteractiveService orchestratorInteractiveService,
     ICdkProjectHandler cdkProjectHandler,
     ICDKManager cdkManager,
     ICDKVersionDetector cdkVersionDetector,
     IDeploymentBundleHandler deploymentBundleHandler,
     IDockerEngine dockerEngine,
     IAWSResourceQueryer awsResourceQueryer,
     ITemplateMetadataReader templateMetadataReader,
     IDeployedApplicationQueryer deployedApplicationQueryer,
     ITypeHintCommandFactory typeHintCommandFactory,
     IDisplayedResourcesHandler displayedResourcesHandler,
     ICloudApplicationNameGenerator cloudApplicationNameGenerator,
     ILocalUserSettingsEngine localUserSettingsEngine,
     IConsoleUtilities consoleUtilities,
     ICustomRecipeLocator customRecipeLocator,
     ISystemCapabilityEvaluator systemCapabilityEvaluator,
     OrchestratorSession session,
     IDirectoryManager directoryManager)
 {
     _toolInteractiveService         = toolInteractiveService;
     _orchestratorInteractiveService = orchestratorInteractiveService;
     _cdkProjectHandler             = cdkProjectHandler;
     _deploymentBundleHandler       = deploymentBundleHandler;
     _dockerEngine                  = dockerEngine;
     _awsResourceQueryer            = awsResourceQueryer;
     _templateMetadataReader        = templateMetadataReader;
     _deployedApplicationQueryer    = deployedApplicationQueryer;
     _typeHintCommandFactory        = typeHintCommandFactory;
     _displayedResourcesHandler     = displayedResourcesHandler;
     _cloudApplicationNameGenerator = cloudApplicationNameGenerator;
     _localUserSettingsEngine       = localUserSettingsEngine;
     _consoleUtilities              = consoleUtilities;
     _session                   = session;
     _directoryManager          = directoryManager;
     _cdkVersionDetector        = cdkVersionDetector;
     _cdkManager                = cdkManager;
     _customRecipeLocator       = customRecipeLocator;
     _systemCapabilityEvaluator = systemCapabilityEvaluator;
 }
        public async Task<List<Repository>> GetECRRepositories(OrchestratorSession session, List<string> repositoryNames)
        {
            var ecrClient = _awsClientFactory.GetAWSClient<IAmazonECR>(session.AWSCredentials, session.AWSRegion);

            var request = new DescribeRepositoriesRequest
            {
                RepositoryNames = repositoryNames
            };

            try
            {
                return await ecrClient.Paginators
                    .DescribeRepositories(request)
                    .Repositories
                    .ToListAsync();
            }
            catch (RepositoryNotFoundException)
            {
                return new List<Repository>();
            }
        }
示例#25
0
 public GenerateDeploymentProjectCommand(
     IToolInteractiveService toolInteractiveService,
     IConsoleUtilities consoleUtilities,
     ICdkProjectHandler cdkProjectHandler,
     ICommandLineWrapper commandLineWrapper,
     IDirectoryManager directoryManager,
     IFileManager fileManager,
     OrchestratorSession session,
     IDeploymentManifestEngine deploymentManifestEngine,
     string targetApplicationFullPath)
 {
     _toolInteractiveService = toolInteractiveService;
     _consoleUtilities       = consoleUtilities;
     _cdkProjectHandler      = cdkProjectHandler;
     _commandLineWrapper     = commandLineWrapper;
     _directoryManager       = directoryManager;
     _fileManager            = fileManager;
     _session = session;
     _deploymentManifestEngine  = deploymentManifestEngine;
     _targetApplicationFullPath = targetApplicationFullPath;
 }
示例#26
0
        public SetOptionSettingTests()
        {
            var projectPath = SystemIOUtilities.ResolvePath("WebAppNoDockerFile");

            var parser         = new ProjectDefinitionParser(new FileManager(), new DirectoryManager());
            var awsCredentials = new Mock <AWSCredentials>();
            var session        = new OrchestratorSession(
                parser.Parse(projectPath).Result,
                awsCredentials.Object,
                "us-west-2",
                "123456789012")
            {
                AWSProfileName = "default"
            };

            var engine          = new RecommendationEngine(new[] { RecipeLocator.FindRecipeDefinitionsPath() }, session);
            var recommendations = engine.ComputeRecommendations().GetAwaiter().GetResult();

            _recommendation = recommendations.First(r => r.Recipe.Id == Constants.ASPNET_CORE_BEANSTALK_RECIPE_ID);

            _optionSetting = _recommendation.Recipe.OptionSettings.First(x => x.Id.Equals("EnvironmentType"));
        }
 public ECSClusterCommand(IAWSResourceQueryer awsResourceQueryer, OrchestratorSession session, ConsoleUtilities consoleUtilities)
 {
     _awsResourceQueryer = awsResourceQueryer;
     _session            = session;
     _consoleUtilities   = consoleUtilities;
 }
 public Task <List <Role> > ListOfIAMRoles(OrchestratorSession session, string servicePrincipal) => throw new NotImplementedException();
示例#29
0
        private static async Task <int> Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            SetExecutionEnvironment();

            var preambleWriter = new ConsoleInteractiveServiceImpl(diagnosticLoggingEnabled: false);

            preambleWriter.WriteLine("AWS .NET deployment tool for deploying .NET Core applications to AWS.");
            preambleWriter.WriteLine("Project Home: https://github.com/aws/aws-dotnet-deploy");
            preambleWriter.WriteLine(string.Empty);

            // Name is important to set here to show correctly in the CLI usage help.
            // Either dotnet-aws or dotnet aws works from the CLI. System.Commandline's help system does not like having a space with dotnet aws.
            var rootCommand = new RootCommand {
                Name = "dotnet-aws", Description = "The AWS .NET deployment tool for deploying .NET applications on AWS."
            };

            var deployCommand = new Command(
                "deploy",
                "Inspect, build, and deploy the .NET project to AWS using the recommended AWS service.")
            {
                _optionProfile,
                _optionRegion,
                _optionProjectPath,
                _optionDiagnosticLogging
            };

            deployCommand.Handler = CommandHandler.Create <string, string, string, bool, bool>(async(profile, region, projectPath, saveCdkProject, diagnostics) =>
            {
                var toolInteractiveService = new ConsoleInteractiveServiceImpl(diagnostics);

                try
                {
                    var orchestratorInteractiveService = new ConsoleOrchestratorLogger(toolInteractiveService);

                    var previousSettings = PreviousDeploymentSettings.ReadSettings(projectPath, null);

                    var awsUtilities   = new AWSUtilities(toolInteractiveService);
                    var awsCredentials = await awsUtilities.ResolveAWSCredentials(profile, previousSettings.Profile);
                    var awsRegion      = awsUtilities.ResolveAWSRegion(region, previousSettings.Region);

                    var commandLineWrapper =
                        new CommandLineWrapper(
                            orchestratorInteractiveService,
                            awsCredentials,
                            awsRegion);

                    var directoryManager     = new DirectoryManager();
                    var fileManager          = new FileManager();
                    var packageJsonGenerator = new PackageJsonGenerator(
                        typeof(PackageJsonGenerator).Assembly
                        .ReadEmbeddedFile(PackageJsonGenerator.TemplateIdentifier));
                    var npmPackageInitializer = new NPMPackageInitializer(commandLineWrapper, packageJsonGenerator, fileManager, directoryManager);
                    var cdkInstaller          = new CDKInstaller(commandLineWrapper);
                    var cdkManager            = new CDKManager(cdkInstaller, npmPackageInitializer);

                    var systemCapabilityEvaluator = new SystemCapabilityEvaluator(commandLineWrapper, cdkManager);
                    var systemCapabilities        = systemCapabilityEvaluator.Evaluate();

                    var stsClient      = new AmazonSecurityTokenServiceClient(awsCredentials);
                    var callerIdentity = await stsClient.GetCallerIdentityAsync(new GetCallerIdentityRequest());

                    var session = new OrchestratorSession
                    {
                        AWSProfileName     = profile,
                        AWSCredentials     = awsCredentials,
                        AWSRegion          = awsRegion,
                        AWSAccountId       = callerIdentity.Account,
                        ProjectPath        = projectPath,
                        ProjectDirectory   = projectPath,
                        SystemCapabilities = systemCapabilities,
                        CdkManager         = cdkManager
                    };

                    var awsResourceQueryer = new AWSResourceQueryer(new DefaultAWSClientFactory());
                    var zipFileManager     = new ZipFileManager(commandLineWrapper);

                    var deploy = new DeployCommand(
                        toolInteractiveService,
                        orchestratorInteractiveService,
                        new CdkProjectHandler(orchestratorInteractiveService, commandLineWrapper),
                        new DeploymentBundleHandler(session, commandLineWrapper, awsResourceQueryer, orchestratorInteractiveService, directoryManager, zipFileManager),
                        awsResourceQueryer,
                        session);

                    await deploy.ExecuteAsync(saveCdkProject);

                    return(CommandReturnCodes.SUCCESS);
                }
                catch (Exception e) when(e.IsAWSDeploymentExpectedException())
                {
                    // helpful error message should have already been presented to the user,
                    // bail out with an non-zero return code.
                    return(CommandReturnCodes.USER_ERROR);
                }
                catch (Exception e)
                {
                    // This is a bug
                    toolInteractiveService.WriteErrorLine(
                        "Unhandled exception.  This is a bug.  Please copy the stack trace below and file a bug at https://github.com/aws/aws-dotnet-deploy. " +
                        e.PrettyPrint());

                    return(CommandReturnCodes.UNHANDLED_EXCEPTION);
                }
            });
            rootCommand.Add(deployCommand);

            var listCommand = new Command("list-deployments", "List existing deployments.")
            {
                _optionProfile,
                _optionRegion,
                _optionProjectPath,
                _optionDiagnosticLogging
            };

            listCommand.Handler = CommandHandler.Create <string, string, string, bool>(async(profile, region, projectPath, diagnostics) =>
            {
                var toolInteractiveService         = new ConsoleInteractiveServiceImpl(diagnostics);
                var orchestratorInteractiveService = new ConsoleOrchestratorLogger(toolInteractiveService);

                var awsUtilities = new AWSUtilities(toolInteractiveService);

                var previousSettings = PreviousDeploymentSettings.ReadSettings(projectPath, null);

                var awsCredentials = await awsUtilities.ResolveAWSCredentials(profile, previousSettings.Profile);
                var awsRegion      = awsUtilities.ResolveAWSRegion(region, previousSettings.Region);

                var stsClient      = new AmazonSecurityTokenServiceClient(awsCredentials);
                var callerIdentity = await stsClient.GetCallerIdentityAsync(new GetCallerIdentityRequest());

                var session = new OrchestratorSession
                {
                    AWSProfileName   = profile,
                    AWSCredentials   = awsCredentials,
                    AWSRegion        = awsRegion,
                    AWSAccountId     = callerIdentity.Account,
                    ProjectPath      = projectPath,
                    ProjectDirectory = projectPath
                };

                var commandLineWrapper =
                    new CommandLineWrapper(
                        orchestratorInteractiveService,
                        awsCredentials,
                        awsRegion);

                var awsResourceQueryer = new AWSResourceQueryer(new DefaultAWSClientFactory());
                var directoryManager   = new DirectoryManager();
                var zipFileManager     = new ZipFileManager(commandLineWrapper);

                await new ListDeploymentsCommand(toolInteractiveService,
                                                 new ConsoleOrchestratorLogger(toolInteractiveService),
                                                 new CdkProjectHandler(orchestratorInteractiveService, commandLineWrapper),
                                                 new DeploymentBundleHandler(session, commandLineWrapper, awsResourceQueryer, orchestratorInteractiveService, directoryManager, zipFileManager),
                                                 awsResourceQueryer,
                                                 session).ExecuteAsync();
            });
            rootCommand.Add(listCommand);

            var deleteCommand = new Command("delete-deployment", "Delete an existing deployment.")
            {
                _optionProfile,
                _optionRegion,
                _optionProjectPath,
                _optionDiagnosticLogging,
                new Argument("deployment-name")
            };

            deleteCommand.Handler = CommandHandler.Create <string, string, string, string, bool>(async(profile, region, projectPath, deploymentName, diagnostics) =>
            {
                var toolInteractiveService = new ConsoleInteractiveServiceImpl(diagnostics);
                var awsUtilities           = new AWSUtilities(toolInteractiveService);

                var previousSettings = PreviousDeploymentSettings.ReadSettings(projectPath, null);

                var awsCredentials = await awsUtilities.ResolveAWSCredentials(profile, previousSettings.Profile);
                var awsRegion      = awsUtilities.ResolveAWSRegion(region, previousSettings.Region);

                var session = new OrchestratorSession
                {
                    AWSProfileName = profile,
                    AWSCredentials = awsCredentials,
                    AWSRegion      = awsRegion,
                };

                await new DeleteDeploymentCommand(new DefaultAWSClientFactory(), toolInteractiveService, session).ExecuteAsync(deploymentName);

                return(CommandReturnCodes.SUCCESS);
            });
            rootCommand.Add(deleteCommand);

            // if user didn't specify a command, default to help
            if (args.Length == 0)
            {
                args = new string[] { "-h" };
            }

            return(await rootCommand.InvokeAsync(args));
        }
 public TypeHintCommandFactory(IToolInteractiveService toolInteractiveService, IAWSResourceQueryer awsResourceQueryer, OrchestratorSession session, ConsoleUtilities consoleUtilities)
 {
     _commands = new Dictionary <OptionSettingTypeHint, ITypeHintCommand>()
     {
         { OptionSettingTypeHint.BeanstalkApplication, new BeanstalkApplicationCommand(toolInteractiveService, awsResourceQueryer, session, consoleUtilities) },
         { OptionSettingTypeHint.BeanstalkEnvironment, new BeanstalkEnvironmentCommand(toolInteractiveService, awsResourceQueryer, session, consoleUtilities) },
         { OptionSettingTypeHint.DotnetBeanstalkPlatformArn, new DotnetBeanstalkPlatformArnCommand(toolInteractiveService, awsResourceQueryer, session, consoleUtilities) },
         { OptionSettingTypeHint.EC2KeyPair, new EC2KeyPairCommand(toolInteractiveService, awsResourceQueryer, session, consoleUtilities) },
         { OptionSettingTypeHint.IAMRole, new IAMRoleCommand(toolInteractiveService, awsResourceQueryer, session, consoleUtilities) },
         { OptionSettingTypeHint.Vpc, new VpcCommand(toolInteractiveService, awsResourceQueryer, session, consoleUtilities) },
         { OptionSettingTypeHint.DotnetPublishAdditionalBuildArguments, new DotnetPublishArgsCommand(consoleUtilities) },
         { OptionSettingTypeHint.DotnetPublishSelfContainedBuild, new DotnetPublishSelfContainedBuildCommand(consoleUtilities) },
         { OptionSettingTypeHint.DotnetPublishBuildConfiguration, new DotnetPublishBuildConfigurationCommand(consoleUtilities) },
         { OptionSettingTypeHint.DockerExecutionDirectory, new DockerExecutionDirectoryCommand(consoleUtilities) },
         { OptionSettingTypeHint.DockerBuildArgs, new DockerBuildArgsCommand(consoleUtilities) },
         { OptionSettingTypeHint.ECSCluster, new ECSClusterCommand(awsResourceQueryer, session, consoleUtilities) },
     };
 }