Skip to content

Commit

Permalink
Merge pull request #247 from aws/dev
Browse files Browse the repository at this point in the history
Release 0.11
  • Loading branch information
philasmar authored Jun 28, 2021
2 parents 95a3b61 + a7ab73d commit 4c54128
Show file tree
Hide file tree
Showing 68 changed files with 1,417 additions and 210 deletions.
10 changes: 4 additions & 6 deletions src/AWS.Deploy.CLI/AWSUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace AWS.Deploy.CLI
{
public interface IAWSUtilities
{
Task<AWSCredentials> ResolveAWSCredentials(string profileName, string? lastUsedProfileName);
string ResolveAWSRegion(string region, string? lastRegionUsed);
Task<AWSCredentials> ResolveAWSCredentials(string? profileName, string? lastUsedProfileName = null);
string ResolveAWSRegion(string? region, string? lastRegionUsed = null);
}

public class AWSUtilities : IAWSUtilities
Expand All @@ -29,10 +29,8 @@ public AWSUtilities(IToolInteractiveService toolInteractiveService, IConsoleUtil
_consoleUtilities = consoleUtilities;
}

public async Task<AWSCredentials> ResolveAWSCredentials(string profileName, string? lastUsedProfileName)
public async Task<AWSCredentials> ResolveAWSCredentials(string? profileName, string? lastUsedProfileName = null)
{


async Task<AWSCredentials> Resolve()
{
var chain = new CredentialProfileStoreChain();
Expand Down Expand Up @@ -113,7 +111,7 @@ private async Task<bool> CanLoadCredentials(AWSCredentials credentials)
}
}

public string ResolveAWSRegion(string region, string? lastRegionUsed)
public string ResolveAWSRegion(string? region, string? lastRegionUsed = null)
{
if (!string.IsNullOrEmpty(region))
{
Expand Down
69 changes: 40 additions & 29 deletions src/AWS.Deploy.CLI/Commands/CommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using AWS.Deploy.Orchestration.CDK;
using AWS.Deploy.Orchestration.Data;
using AWS.Deploy.Orchestration.Utilities;
using AWS.Deploy.CLI.Commands.CommandHandlerInput;

namespace AWS.Deploy.CLI.Commands
{
Expand All @@ -29,6 +30,8 @@ public class CommandFactory : ICommandFactory
private static readonly Option<string> _optionProjectPath = new("--project-path", () => Directory.GetCurrentDirectory(), "Path to the project to deploy.");
private static readonly Option<string> _optionStackName = new("--stack-name", "Name the AWS stack to deploy your application to.");
private static readonly Option<bool> _optionDiagnosticLogging = new(new []{"-d", "--diagnostics"}, "Enable diagnostic output.");
private static readonly Option<string> _optionApply = new("--apply", "Path to the deployment settings file to be applied.");
private static readonly Option<bool> _optionDisableInteractive = new(new []{"-s", "--silent" }, "Disable interactivity to deploy without any prompts for user input.");

private readonly IToolInteractiveService _toolInteractiveService;
private readonly IOrchestratorInteractiveService _orchestratorInteractiveService;
Expand Down Expand Up @@ -110,26 +113,31 @@ private Command BuildDeployCommand()
_optionRegion,
_optionProjectPath,
_optionStackName,
_optionApply,
_optionDiagnosticLogging,
_optionDisableInteractive
};

deployCommand.Handler = CommandHandler.Create<string, string, string, string, bool, bool>(async (profile, region, projectPath, stackName, saveCdkProject, diagnostics) =>
deployCommand.Handler = CommandHandler.Create(async (DeployCommandHandlerInput input) =>
{
try
{
_toolInteractiveService.Diagnostics = diagnostics;
_toolInteractiveService.Diagnostics = input.Diagnostics;
_toolInteractiveService.DisableInteractive = input.Silent;

var userDeploymentSettings = !string.IsNullOrEmpty(input.Apply)
? UserDeploymentSettings.ReadSettings(input.Apply)
: null;

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

var awsCredentials = await _awsUtilities.ResolveAWSCredentials(profile, previousSettings.Profile);
var awsRegion = _awsUtilities.ResolveAWSRegion(region, previousSettings.Region);
var awsCredentials = await _awsUtilities.ResolveAWSCredentials(input.Profile ?? userDeploymentSettings?.AWSProfile);
var awsRegion = _awsUtilities.ResolveAWSRegion(input.Region ?? userDeploymentSettings?.AWSRegion);

_commandLineWrapper.RegisterAWSContext(awsCredentials, awsRegion);
_awsClientFactory.RegisterAWSContext(awsCredentials, awsRegion);

var systemCapabilities = _systemCapabilityEvaluator.Evaluate();

var projectDefinition = await _projectParserUtility.Parse(projectPath);
var projectDefinition = await _projectParserUtility.Parse(input.ProjectPath ?? "");

var callerIdentity = await _awsResourceQueryer.GetCallerIdentity();

Expand All @@ -140,7 +148,7 @@ private Command BuildDeployCommand()
callerIdentity.Account)
{
SystemCapabilities = systemCapabilities,
AWSProfileName = profile
AWSProfileName = input.Profile ?? userDeploymentSettings?.AWSProfile ?? null
};

var dockerEngine = new DockerEngine.DockerEngine(projectDefinition);
Expand All @@ -160,13 +168,13 @@ private Command BuildDeployCommand()
_consoleUtilities,
session);

await deploy.ExecuteAsync(stackName, saveCdkProject);
await deploy.ExecuteAsync(input.StackName ?? "", input.SaveCdkProject, userDeploymentSettings);

return CommandReturnCodes.SUCCESS;
}
catch (Exception e) when (e.IsAWSDeploymentExpectedException())
{
if (diagnostics)
if (input.Diagnostics)
_toolInteractiveService.WriteErrorLine(e.PrettyPrint());
else
{
Expand Down Expand Up @@ -199,30 +207,35 @@ private Command BuildDeleteCommand()
_optionDiagnosticLogging,
new Argument("deployment-name")
};
deleteCommand.Handler = CommandHandler.Create<string, string, string, string, bool>(async (profile, region, projectPath, deploymentName, diagnostics) =>
deleteCommand.Handler = CommandHandler.Create(async (DeleteCommandHandlerInput input) =>
{
try
{
_toolInteractiveService.Diagnostics = diagnostics;

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

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

_awsClientFactory.ConfigureAWSOptions(awsOption =>
{
awsOption.Credentials = awsCredentials;
awsOption.Region = RegionEndpoint.GetBySystemName(awsRegion);
});

await new DeleteDeploymentCommand(_awsClientFactory, _toolInteractiveService, _consoleUtilities).ExecuteAsync(deploymentName);
if (string.IsNullOrEmpty(input.DeploymentName))
{
_toolInteractiveService.WriteErrorLine(string.Empty);
_toolInteractiveService.WriteErrorLine("Deployment name cannot be empty. Please provide a valid deployment name and try again.");
return CommandReturnCodes.USER_ERROR;
}

await new DeleteDeploymentCommand(_awsClientFactory, _toolInteractiveService, _consoleUtilities).ExecuteAsync(input.DeploymentName);

return CommandReturnCodes.SUCCESS;
}
catch (Exception e) when (e.IsAWSDeploymentExpectedException())
{
if (diagnostics)
if (input.Diagnostics)
_toolInteractiveService.WriteErrorLine(e.PrettyPrint());
else
{
Expand Down Expand Up @@ -254,16 +267,14 @@ private Command BuildListCommand()
_optionProjectPath,
_optionDiagnosticLogging
};
listCommand.Handler = CommandHandler.Create<string, string, string, bool>(async (profile, region, projectPath, diagnostics) =>
listCommand.Handler = CommandHandler.Create(async (ListCommandHandlerInput input) =>
{
try
{
_toolInteractiveService.Diagnostics = diagnostics;

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

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

_awsClientFactory.ConfigureAWSOptions(awsOptions =>
{
Expand All @@ -277,7 +288,7 @@ private Command BuildListCommand()
}
catch (Exception e) when (e.IsAWSDeploymentExpectedException())
{
if (diagnostics)
if (input.Diagnostics)
_toolInteractiveService.WriteErrorLine(e.PrettyPrint());
else
{
Expand Down Expand Up @@ -307,20 +318,20 @@ private Command BuildServerModeCommand()
new Option<bool>(new []{"--encryption-keyinfo-stdin"}, description: "If set the cli reads encryption key info from stdin to use for decryption."),
_optionDiagnosticLogging
};
serverModeCommand.Handler = CommandHandler.Create<int, int?, bool, bool>(async (port, parentPid, encryptionKeyInfoStdIn, diagnostics) =>
serverModeCommand.Handler = CommandHandler.Create(async (ServerModeCommandHandlerInput input) =>
{
try
{
var toolInteractiveService = new ConsoleInteractiveServiceImpl(diagnostics);
var serverMode = new ServerModeCommand(toolInteractiveService, port, parentPid, encryptionKeyInfoStdIn);
var toolInteractiveService = new ConsoleInteractiveServiceImpl(input.Diagnostics);
var serverMode = new ServerModeCommand(toolInteractiveService, input.Port, input.ParentPid, input.EncryptionKeyInfoStdIn);

await serverMode.ExecuteAsync();

return CommandReturnCodes.SUCCESS;
}
catch (Exception e) when (e.IsAWSDeploymentExpectedException())
{
if (diagnostics)
if (input.Diagnostics)
_toolInteractiveService.WriteErrorLine(e.PrettyPrint());
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AWS.Deploy.CLI.Commands.CommandHandlerInput
{
public class DeleteCommandHandlerInput
{
public string? Profile { get; set; }
public string? Region { get; set; }
public string? ProjectPath { get; set; }
public string? DeploymentName { get; set; }
public bool Diagnostics { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AWS.Deploy.CLI.Commands.CommandHandlerInput
{
public class DeployCommandHandlerInput
{
public string? Profile { get; set; }
public string? Region { get; set; }
public string? ProjectPath { get; set; }
public string? StackName { get; set; }
public string? Apply { get; set; }
public bool Diagnostics { get; set; }
public bool Silent { get; set; }
public bool SaveCdkProject { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AWS.Deploy.CLI.Commands.CommandHandlerInput
{
public class ListCommandHandlerInput
{
public string? Profile { get; set; }
public string? Region { get; set; }
public string? ProjectPath { get; set; }
public bool Diagnostics { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AWS.Deploy.CLI.Commands.CommandHandlerInput
{
public class ServerModeCommandHandlerInput
{
public int Port { get; set; }
public int ParentPid { get; set; }
public bool EncryptionKeyInfoStdIn { get; set; }
public bool Diagnostics { get; set; }
}
}
Loading

0 comments on commit 4c54128

Please sign in to comment.