Skip to content

Commit

Permalink
Merge pull request #308 from aws/dev
Browse files Browse the repository at this point in the history
chore: release 0.17
  • Loading branch information
philasmar authored Aug 27, 2021
2 parents 2ac2770 + eed02cb commit 2a95cce
Show file tree
Hide file tree
Showing 76 changed files with 2,026 additions and 389 deletions.
2 changes: 1 addition & 1 deletion src/AWS.Deploy.CLI/CloudFormation/StackEventMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class StackEventMonitor
private const int RESOURCE_STATUS_WIDTH = 20;
private const int RESOURCE_TYPE_WIDTH = 40;
private const int LOGICAL_RESOURCE_WIDTH = 40;
private static readonly TimeSpan s_pollingPeriod = TimeSpan.FromSeconds(2);
private static readonly TimeSpan s_pollingPeriod = TimeSpan.FromSeconds(5);

private readonly string _stackName;
private bool _isActive;
Expand Down
18 changes: 12 additions & 6 deletions src/AWS.Deploy.CLI/Commands/CommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class CommandFactory : ICommandFactory
private readonly IDeploymentManifestEngine _deploymentManifestEngine;
private readonly ICustomRecipeLocator _customRecipeLocator;
private readonly ILocalUserSettingsEngine _localUserSettingsEngine;
private readonly ICDKVersionDetector _cdkVersionDetector;

public CommandFactory(
IToolInteractiveService toolInteractiveService,
Expand All @@ -90,7 +92,8 @@ public CommandFactory(
IFileManager fileManager,
IDeploymentManifestEngine deploymentManifestEngine,
ICustomRecipeLocator customRecipeLocator,
ILocalUserSettingsEngine localUserSettingsEngine)
ILocalUserSettingsEngine localUserSettingsEngine,
ICDKVersionDetector cdkVersionDetector)
{
_toolInteractiveService = toolInteractiveService;
_orchestratorInteractiveService = orchestratorInteractiveService;
Expand All @@ -114,6 +117,7 @@ public CommandFactory(
_deploymentManifestEngine = deploymentManifestEngine;
_customRecipeLocator = customRecipeLocator;
_localUserSettingsEngine = localUserSettingsEngine;
_cdkVersionDetector = cdkVersionDetector;
}

public Command BuildRootCommand()
Expand Down Expand Up @@ -193,6 +197,7 @@ private Command BuildDeployCommand()
_orchestratorInteractiveService,
_cdkProjectHandler,
_cdkManager,
_cdkVersionDetector,
_deploymentBundleHandler,
dockerEngine,
_awsResourceQueryer,
Expand All @@ -205,7 +210,8 @@ private Command BuildDeployCommand()
_consoleUtilities,
_customRecipeLocator,
_systemCapabilityEvaluator,
session);
session,
_directoryManager);

var deploymentProjectPath = input.DeploymentProject ?? string.Empty;
if (!string.IsNullOrEmpty(deploymentProjectPath))
Expand Down Expand Up @@ -338,7 +344,7 @@ private Command BuildListCommand()
listCommand.Add(_optionRegion);
listCommand.Add(_optionProjectPath);
listCommand.Add(_optionDiagnosticLogging);
}
}

listCommand.Handler = CommandHandler.Create(async (ListCommandHandlerInput input) =>
{
Expand Down Expand Up @@ -478,16 +484,16 @@ private Command BuildServerModeCommand()
{
serverModeCommand.Add(new Option<int>(new[] { "--port" }, description: "Port the server mode will listen to."));
serverModeCommand.Add(new Option<int>(new[] { "--parent-pid" }, description: "The ID of the process that is launching server mode. Server mode will exit when the parent pid terminates."));
serverModeCommand.Add(new Option<bool>(new[] { "--encryption-keyinfo-stdin" }, description: "If set the cli reads encryption key info from stdin to use for decryption."));
serverModeCommand.Add(new Option<bool>(new[] { "--unsecure-mode" }, description: "If set the cli uses an unsecure mode without encryption."));
serverModeCommand.Add(_optionDiagnosticLogging);
}

serverModeCommand.Handler = CommandHandler.Create(async (ServerModeCommandHandlerInput input) =>
{
try
{
var toolInteractiveService = new ConsoleInteractiveServiceImpl(input.Diagnostics);
var serverMode = new ServerModeCommand(toolInteractiveService, input.Port, input.ParentPid, input.EncryptionKeyInfoStdIn);
_toolInteractiveService.Diagnostics = input.Diagnostics;
var serverMode = new ServerModeCommand(_toolInteractiveService, input.Port, input.ParentPid, input.UnsecureMode);

await serverMode.ExecuteAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ServerModeCommandHandlerInput
{
public int Port { get; set; }
public int ParentPid { get; set; }
public bool EncryptionKeyInfoStdIn { get; set; }
public bool UnsecureMode { get; set; }
public bool Diagnostics { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/AWS.Deploy.CLI/Commands/DeleteDeploymentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace AWS.Deploy.CLI.Commands
/// </summary>
public class DeleteDeploymentCommand
{
private static readonly TimeSpan s_pollingPeriod = TimeSpan.FromSeconds(1);
private static readonly TimeSpan s_pollingPeriod = TimeSpan.FromSeconds(5);

private readonly IAWSClientFactory _awsClientFactory;
private readonly IToolInteractiveService _interactiveService;
Expand Down Expand Up @@ -173,7 +173,7 @@ private async Task WaitForStackDelete(string stackName)
{
shouldRetry = false;
}
catch (AmazonCloudFormationException exception) when (exception.ErrorCode.Equals("ThrottlingException"))
catch (AmazonCloudFormationException exception) when (exception.ErrorCode.Equals("Throttling"))
{
_interactiveService.WriteDebugLine(exception.PrettyPrint());
shouldRetry = true;
Expand Down
28 changes: 20 additions & 8 deletions src/AWS.Deploy.CLI/Commands/DeployCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ public class DeployCommand
private readonly ICustomRecipeLocator _customRecipeLocator;
private readonly ISystemCapabilityEvaluator _systemCapabilityEvaluator;
private readonly OrchestratorSession _session;
private readonly IDirectoryManager _directoryManager;
private ICDKVersionDetector _cdkVersionDetector;

public DeployCommand(
IToolInteractiveService toolInteractiveService,
IOrchestratorInteractiveService orchestratorInteractiveService,
ICdkProjectHandler cdkProjectHandler,
ICDKManager cdkManager,
ICDKVersionDetector cdkVersionDetector,
IDeploymentBundleHandler deploymentBundleHandler,
IDockerEngine dockerEngine,
IAWSResourceQueryer awsResourceQueryer,
Expand All @@ -60,7 +63,8 @@ public DeployCommand(
IConsoleUtilities consoleUtilities,
ICustomRecipeLocator customRecipeLocator,
ISystemCapabilityEvaluator systemCapabilityEvaluator,
OrchestratorSession session)
OrchestratorSession session,
IDirectoryManager directoryManager)
{
_toolInteractiveService = toolInteractiveService;
_orchestratorInteractiveService = orchestratorInteractiveService;
Expand All @@ -76,6 +80,8 @@ public DeployCommand(
_localUserSettingsEngine = localUserSettingsEngine;
_consoleUtilities = consoleUtilities;
_session = session;
_directoryManager = directoryManager;
_cdkVersionDetector = cdkVersionDetector;
_cdkManager = cdkManager;
_customRecipeLocator = customRecipeLocator;
_systemCapabilityEvaluator = systemCapabilityEvaluator;
Expand Down Expand Up @@ -136,12 +142,14 @@ private void DisplayOutputResources(List<DisplayedResourceItem> displayedResourc
_orchestratorInteractiveService,
_cdkProjectHandler,
_cdkManager,
_cdkVersionDetector,
_awsResourceQueryer,
_deploymentBundleHandler,
_localUserSettingsEngine,
_dockerEngine,
_customRecipeLocator,
new List<string> { RecipeLocator.FindRecipeDefinitionsPath() });
new List<string> { RecipeLocator.FindRecipeDefinitionsPath() },
_directoryManager);

// Determine what recommendations are possible for the project.
var recommendations = await GenerateDeploymentRecommendations(orchestrator, deploymentProjectPath);
Expand Down Expand Up @@ -170,7 +178,7 @@ private void DisplayOutputResources(List<DisplayedResourceItem> displayedResourc

// preset settings for deployment based on last deployment.
selectedRecommendation = await GetSelectedRecommendationFromPreviousDeployment(recommendations, deployedApplication, userDeploymentSettings);
}
}
else
{
if (!string.IsNullOrEmpty(deploymentProjectPath))
Expand All @@ -182,7 +190,7 @@ private void DisplayOutputResources(List<DisplayedResourceItem> displayedResourc
selectedRecommendation = GetSelectedRecommendation(userDeploymentSettings, recommendations);
}
}

var cloudApplication = new CloudApplication(cloudApplicationName, selectedRecommendation.Recipe.Id);

return (orchestrator, selectedRecommendation, cloudApplication);
Expand Down Expand Up @@ -275,7 +283,7 @@ private async Task<Recommendation> GetSelectedRecommendationFromPreviousDeployme
}
throw new InvalidUserDeploymentSettingsException(errorMessage.Trim());
}

selectedRecommendation = selectedRecommendation.ApplyPreviousSettings(existingCloudApplicationMetadata.Settings);

var header = $"Loading {deployedApplication.Name} settings:";
Expand Down Expand Up @@ -337,6 +345,9 @@ private void ConfigureDeploymentFromConfigFile(Recommendation recommendation, Us
case OptionSettingValueType.Bool:
settingValue = bool.Parse(optionSettingValue);
break;
case OptionSettingValueType.Double:
settingValue = double.Parse(optionSettingValue);
break;
default:
throw new InvalidOverrideValueException($"Invalid value {optionSettingValue} for option setting item {optionSettingJsonPath}");
}
Expand Down Expand Up @@ -437,7 +448,7 @@ private string GetCloudApplicationName(string? stackName, UserDeploymentSettings
private Recommendation GetSelectedRecommendation(UserDeploymentSettings? userDeploymentSettings, List<Recommendation> recommendations)
{
var deploymentSettingsRecipeId = userDeploymentSettings?.RecipeId;

if (string.IsNullOrEmpty(deploymentSettingsRecipeId))
{
if (_toolInteractiveService.DisableInteractive)
Expand All @@ -450,13 +461,13 @@ private Recommendation GetSelectedRecommendation(UserDeploymentSettings? userDep
}
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;
Expand Down Expand Up @@ -710,6 +721,7 @@ private async Task ConfigureDeploymentFromCli(Recommendation recommendation, Opt
{
case OptionSettingValueType.String:
case OptionSettingValueType.Int:
case OptionSettingValueType.Double:
settingValue = _consoleUtilities.AskUserForValue(string.Empty, currentValue.ToString() ?? "", allowEmpty: true, resetValue: recommendation.GetOptionSettingDefaultValue<string>(setting) ?? "");
break;
case OptionSettingValueType.Bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public async Task ExecuteAsync(string saveCdkDirectoryPath, string projectDispla
}
}

_cdkProjectHandler.CreateCdkProjectForDeployment(selectedRecommendation, _session, saveCdkDirectoryPath);
_cdkProjectHandler.CreateCdkProject(selectedRecommendation, _session, saveCdkDirectoryPath);
await GenerateDeploymentRecipeSnapShot(selectedRecommendation, saveCdkDirectoryPath, projectDisplayName);

var saveCdkDirectoryFullPath = _directoryManager.GetDirectoryInfo(saveCdkDirectoryPath).FullName;
Expand Down
22 changes: 11 additions & 11 deletions src/AWS.Deploy.CLI/Commands/ServerModeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public class ServerModeCommand
private readonly IToolInteractiveService _interactiveService;
private readonly int _port;
private readonly int? _parentPid;
private readonly bool _encryptionKeyInfoStdIn;
private readonly bool _noEncryptionKeyInfo;

public ServerModeCommand(IToolInteractiveService interactiveService, int port, int? parentPid, bool encryptionKeyInfoStdIn)
public ServerModeCommand(IToolInteractiveService interactiveService, int port, int? parentPid, bool noEncryptionKeyInfo)
{
_interactiveService = interactiveService;
_port = port;
_parentPid = parentPid;
_encryptionKeyInfoStdIn = encryptionKeyInfoStdIn;
_noEncryptionKeyInfo = noEncryptionKeyInfo;
}

public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
Expand Down Expand Up @@ -85,9 +85,13 @@ private async Task ShutDownHost(IWebHost host, CancellationToken cancellationTok
private IEncryptionProvider CreateEncryptionProvider()
{
IEncryptionProvider encryptionProvider;
if (_encryptionKeyInfoStdIn)
if (_noEncryptionKeyInfo)
{
_interactiveService.WriteLine("Waiting on encryption key info from stdin");
encryptionProvider = new NoEncryptionProvider();
}
else
{
_interactiveService.WriteLine("Waiting on symmetric key from stdin");
var input = _interactiveService.ReadLine();
var keyInfo = EncryptionKeyInfo.ParseStdInKeyInfo(input);

Expand All @@ -108,17 +112,13 @@ private IEncryptionProvider CreateEncryptionProvider()
encryptionProvider = new AesEncryptionProvider(aes);
break;
case null:
throw new InvalidEncryptionKeyInfoException("Missing required \"Version\" property in encryption key info");
throw new InvalidEncryptionKeyInfoException("Missing required \"Version\" property in the symmetric key");
default:
throw new InvalidEncryptionKeyInfoException($"Unsupported encryption key info {keyInfo.Version}");
throw new InvalidEncryptionKeyInfoException($"Unsupported symmetric key {keyInfo.Version}");
}

_interactiveService.WriteLine("Encryption provider enabled");
}
else
{
encryptionProvider = new NoEncryptionProvider();
}

return encryptionProvider;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using System.Threading.Tasks;
using Amazon.ElasticLoadBalancingV2;
using Amazon.ElasticLoadBalancingV2.Model;
using AWS.Deploy.CLI.TypeHintResponses;
using AWS.Deploy.Common;
using AWS.Deploy.Common.Recipes;
using AWS.Deploy.Orchestration.Data;

namespace AWS.Deploy.CLI.Commands.TypeHints
{
public class ExistingApplicationLoadBalancerCommand : ITypeHintCommand
{
private readonly IAWSResourceQueryer _awsResourceQueryer;
private readonly IConsoleUtilities _consoleUtilities;

public ExistingApplicationLoadBalancerCommand(IAWSResourceQueryer awsResourceQueryer, IConsoleUtilities consoleUtilities)
{
_awsResourceQueryer = awsResourceQueryer;
_consoleUtilities = consoleUtilities;
}

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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public TypeHintCommandFactory(IToolInteractiveService toolInteractiveService, IA
{ OptionSettingTypeHint.DockerExecutionDirectory, new DockerExecutionDirectoryCommand(consoleUtilities) },
{ OptionSettingTypeHint.DockerBuildArgs, new DockerBuildArgsCommand(consoleUtilities) },
{ OptionSettingTypeHint.ECSCluster, new ECSClusterCommand(awsResourceQueryer, consoleUtilities) },
{ OptionSettingTypeHint.ExistingApplicationLoadBalancer, new ExistingApplicationLoadBalancerCommand(awsResourceQueryer, consoleUtilities) },
};
}

Expand Down
9 changes: 1 addition & 8 deletions src/AWS.Deploy.CLI/ConsoleInteractiveServiceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ namespace AWS.Deploy.CLI
{
public class ConsoleInteractiveServiceImpl : IToolInteractiveService
{
private readonly bool _diagnosticLoggingEnabled;

public ConsoleInteractiveServiceImpl(bool diagnosticLoggingEnabled = false)
{
_diagnosticLoggingEnabled = diagnosticLoggingEnabled;
}

public string ReadLine()
{
return Console.ReadLine() ?? string.Empty;
Expand All @@ -24,7 +17,7 @@ public string ReadLine()

public void WriteDebugLine(string? message)
{
if (_diagnosticLoggingEnabled)
if (Diagnostics)
Console.WriteLine($"DEBUG: {message}");
}

Expand Down
4 changes: 2 additions & 2 deletions src/AWS.Deploy.CLI/ConsoleUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ public void DisplayValues(Dictionary<string, object> objectValues, string indent
_interactiveService.WriteLine($"{indent}{key}: {stringValue}");
}
}
else if (value is bool boolValue)
else if(value != null)
{
_interactiveService.WriteLine($"{indent}{key}: {boolValue}");
_interactiveService.WriteLine($"{indent}{key}: {value}");
}
}
}
Expand Down
Loading

0 comments on commit 2a95cce

Please sign in to comment.