private IServiceProvider CreateSessionServiceProvider(string sessionId, string awsRegion) { var awsCredentials = HttpContext.User.ToAWSCredentials(); if (awsCredentials == null) { throw new FailedToRetrieveAWSCredentialsException("AWS credentials are missing for the current session."); } var interactiveServices = new SessionOrchestratorInteractiveService(sessionId, _hubContext); var services = new ServiceCollection(); services.AddSingleton <IOrchestratorInteractiveService>(interactiveServices); services.AddSingleton <ICommandLineWrapper>(services => { var wrapper = new CommandLineWrapper(interactiveServices, true); wrapper.RegisterAWSContext(awsCredentials, awsRegion); return(wrapper); }); services.AddCustomServices(); var serviceProvider = services.BuildServiceProvider(); var awsClientFactory = serviceProvider.GetRequiredService <IAWSClientFactory>(); awsClientFactory.ConfigureAWSOptions(awsOptions => { awsOptions.Credentials = awsCredentials; awsOptions.Region = RegionEndpoint.GetBySystemName(awsRegion); }); return(serviceProvider); }
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)); }
public void GetResults_When_OutputArgsAreNotPassed_ReturnsNull_AndWritesHelpTextToConsole(params string[] args) { _sut = new CommandLineWrapper(); var result = _sut.GetResult(args); Assert.Null(result); }
private ICustomRecipeLocator BuildCustomRecipeLocator() { var directoryManager = new DirectoryManager(); var fileManager = new FileManager(); var deploymentManifestEngine = new DeploymentManifestEngine(directoryManager, fileManager); var consoleInteractiveServiceImpl = new ConsoleInteractiveServiceImpl(); var consoleOrchestratorLogger = new ConsoleOrchestratorLogger(consoleInteractiveServiceImpl); var commandLineWrapper = new CommandLineWrapper(consoleOrchestratorLogger); return(new CustomRecipeLocator(deploymentManifestEngine, consoleOrchestratorLogger, commandLineWrapper, directoryManager)); }
public async Task RecipeController_GetRecipe_EmptyId(string recipeId) { var directoryManager = new DirectoryManager(); var fileManager = new FileManager(); var deploymentManifestEngine = new DeploymentManifestEngine(directoryManager, fileManager); var consoleInteractiveServiceImpl = new ConsoleInteractiveServiceImpl(); var consoleOrchestratorLogger = new ConsoleOrchestratorLogger(consoleInteractiveServiceImpl); var commandLineWrapper = new CommandLineWrapper(consoleOrchestratorLogger); var customRecipeLocator = new CustomRecipeLocator(deploymentManifestEngine, consoleOrchestratorLogger, commandLineWrapper, directoryManager); var projectDefinitionParser = new ProjectDefinitionParser(fileManager, directoryManager); var recipeController = new RecipeController(customRecipeLocator, projectDefinitionParser); var response = await recipeController.GetRecipe(recipeId); Assert.IsType <BadRequestObjectResult>(response); }
public void GetResults_When_CorrectArgsArePassed_ReturnsCorrectOptions() { // Arrange var beginWord = "SORT"; var targetWord = "HIRE"; var inputFileName = "c:\\input"; ; var outputFileName = "c:\\output"; var args = new[] { beginWord, targetWord, inputFileName, outputFileName }; var expectedResult = new Options(beginWord, targetWord, inputFileName, outputFileName); _sut = new CommandLineWrapper(); var result = _sut.GetResult(args); result.Should().BeEquivalentTo(expectedResult); }
public async Task RecipeController_GetRecipe_HappyPath() { var directoryManager = new DirectoryManager(); var fileManager = new FileManager(); var deploymentManifestEngine = new DeploymentManifestEngine(directoryManager, fileManager); var consoleInteractiveServiceImpl = new ConsoleInteractiveServiceImpl(); var consoleOrchestratorLogger = new ConsoleOrchestratorLogger(consoleInteractiveServiceImpl); var commandLineWrapper = new CommandLineWrapper(consoleOrchestratorLogger); var customRecipeLocator = new CustomRecipeLocator(deploymentManifestEngine, consoleOrchestratorLogger, commandLineWrapper, directoryManager); var projectDefinitionParser = new ProjectDefinitionParser(fileManager, directoryManager); var recipeController = new RecipeController(customRecipeLocator, projectDefinitionParser); var recipeDefinitions = await RecipeHandler.GetRecipeDefinitions(customRecipeLocator, null); var recipe = recipeDefinitions.First(); var response = await recipeController.GetRecipe(recipe.Id); var result = Assert.IsType <OkObjectResult>(response); var resultRecipe = Assert.IsType <RecipeSummary>(result.Value); Assert.Equal(recipe.Id, resultRecipe.Id); }
public async Task InitializeAsync() { var scriptPath = Path.Combine("..", "..", "..", "DeploymentScript.ps1"); await CommandLineWrapper.RunAsync($"pwsh {scriptPath}"); _stackName = GetStackName(); _bucketName = GetBucketName(); Assert.False(string.IsNullOrEmpty(_stackName)); Assert.False(string.IsNullOrEmpty(_bucketName)); RestApiUrlPrefix = await _cloudFormationHelper.GetOutputValueAsync(_stackName, "RestApiURL"); HttpApiUrlPrefix = await _cloudFormationHelper.GetOutputValueAsync(_stackName, "HttpApiURL"); LambdaFunctions = await LambdaHelper.FilterByCloudFormationStackAsync(_stackName); Assert.Equal(StackStatus.CREATE_COMPLETE, await _cloudFormationHelper.GetStackStatusAsync(_stackName)); Assert.True(await _s3Helper.BucketExistsAsync(_bucketName)); Assert.Equal(13, LambdaFunctions.Count); Assert.False(string.IsNullOrEmpty(RestApiUrlPrefix)); Assert.False(string.IsNullOrEmpty(RestApiUrlPrefix)); await LambdaHelper.WaitTillNotPending(LambdaFunctions.Select(x => x.Name).ToList()); }
public RecommendationTests() { _commandLineWrapper = new CommandLineWrapper(new ConsoleOrchestratorLogger(new ConsoleInteractiveServiceImpl())); }
public SaveCdkDeploymentProjectTests() { _commandLineWrapper = new CommandLineWrapper(new ConsoleOrchestratorLogger(new ConsoleInteractiveServiceImpl())); }
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 CustomRecipeLocatorTests() { _commandLineWrapper = new CommandLineWrapper(new ConsoleOrchestratorLogger(new ConsoleInteractiveServiceImpl())); }