Skip to content

Commit

Permalink
Merge pull request #400 from aws/dev
Browse files Browse the repository at this point in the history
chore: release 0.30
  • Loading branch information
philasmar authored Nov 9, 2021
2 parents 659d16a + 8af0f55 commit 6c508ac
Show file tree
Hide file tree
Showing 48 changed files with 338 additions and 265 deletions.
4 changes: 2 additions & 2 deletions src/AWS.Deploy.CLI/AWSUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ await CanLoadCredentials(lastUsedCredentials))
var sharedCredentials = new SharedCredentialsFile();
if (sharedCredentials.ListProfileNames().Count == 0)
{
throw new NoAWSCredentialsFoundException("Unable to resolve AWS credentials to access AWS.");
throw new NoAWSCredentialsFoundException(DeployToolErrorCode.UnableToResolveAWSCredentials, "Unable to resolve AWS credentials to access AWS.");
}

var selectedProfileName = _consoleUtilities.AskUserToChoose(sharedCredentials.ListProfileNames(), "Select AWS Credentials Profile", null);
Expand All @@ -91,7 +91,7 @@ await CanLoadCredentials(lastUsedCredentials))
return selectedProfileCredentials;
}

throw new NoAWSCredentialsFoundException($"Unable to create AWS credentials for profile {selectedProfileName}.");
throw new NoAWSCredentialsFoundException(DeployToolErrorCode.UnableToCreateAWSCredentials, $"Unable to create AWS credentials for profile {selectedProfileName}.");
}

var credentials = await Resolve();
Expand Down
8 changes: 4 additions & 4 deletions src/AWS.Deploy.CLI/CommandReturnCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public class CommandReturnCodes
/// exception was thrown. This usually means there is an intermittent io problem
/// or bug in the code base.
/// <para />
/// Unexpected exception are any exception not marked by
/// <see cref="AWSDeploymentExpectedExceptionAttribute"/>
/// Unexpected exceptions are any exception that do not inherit from
/// <see cref="DeployToolException"/>
/// </summary>
public const int UNHANDLED_EXCEPTION = -1;
/// <summary>
/// A command could not finish of an expected problem like a user
/// configuration or system configuration problem. For example, a required
/// dependency like Docker is not installed.
/// <para />
/// Expected problems are usually indicated by throwing an exception that is
/// decorated with <see cref="AWSDeploymentExpectedExceptionAttribute"/>
/// Expected problems are usually indicated by throwing an exception that
/// inherits from <see cref="DeployToolException"/>
/// </summary>
public const int USER_ERROR = 1;
/// <summary>
Expand Down
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 @@ -126,10 +126,10 @@ private async Task WaitForStackDelete(string stackName)

if (stack.StackStatus.IsFailed())
{
throw new FailedToDeleteException($"The stack {stackName} is in a failed state. You may need to delete it from the AWS Console.");
throw new FailedToDeleteException(DeployToolErrorCode.FailedToDeleteStack, $"The stack {stackName} is in a failed state. You may need to delete it from the AWS Console.");
}

throw new FailedToDeleteException($"Failed to delete {stackName} stack: {stack.StackStatus}");
throw new FailedToDeleteException(DeployToolErrorCode.FailedToDeleteStack, $"Failed to delete {stackName} stack: {stack.StackStatus}");
}

private async Task<Stack?> StabilizeStack(string stackName)
Expand Down
36 changes: 18 additions & 18 deletions src/AWS.Deploy.CLI/Commands/DeployCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void DisplayOutputResources(List<DisplayedResourceItem> displayedResourc
if (!compatibleApplications.Any(app => app.StackName.Equals(deployedApplication.StackName, StringComparison.Ordinal)))
{
var errorMessage = $"{deployedApplication.StackName} already exists as a Cloudformation stack but a compatible recommendation to perform a redeployment was not found";
throw new FailedToFindCompatibleRecipeException(errorMessage);
throw new FailedToFindCompatibleRecipeException(DeployToolErrorCode.CompatibleRecommendationForRedeploymentNotFound, errorMessage);
}

// preset settings for deployment based on last deployment.
Expand Down Expand Up @@ -219,7 +219,7 @@ public async Task EvaluateSystemCapabilities(Recommendation selectedRecommendati
}

if (systemCapabilities.Any())
throw new MissingSystemCapabilityException(missingCapabilitiesMessage);
throw new MissingSystemCapabilityException(DeployToolErrorCode.MissingSystemCapabilities, missingCapabilitiesMessage);
}

/// <summary>
Expand Down Expand Up @@ -253,7 +253,7 @@ private async Task<List<Recommendation>> GenerateDeploymentRecommendations(Orche
if (!recommendations.Any())
{
var errorMessage = $"Could not find any deployment recipe located inside '{deploymentProjectPath}' that can be used for deployment of the target application";
throw new FailedToGenerateAnyRecommendations(errorMessage);
throw new FailedToGenerateAnyRecommendations(DeployToolErrorCode.NoDeploymentRecipesFound, errorMessage);
}
}
else
Expand All @@ -262,7 +262,7 @@ private async Task<List<Recommendation>> GenerateDeploymentRecommendations(Orche
if (!recommendations.Any())
{
var errorMessage = "There are no compatible deployment recommendations for this application.";
throw new FailedToGenerateAnyRecommendations(errorMessage);
throw new FailedToGenerateAnyRecommendations(DeployToolErrorCode.NoCompatibleDeploymentRecipesFound, errorMessage);
}
}
return recommendations;
Expand All @@ -276,7 +276,7 @@ private async Task<Recommendation> GetSelectedRecommendationFromPreviousDeployme
if (selectedRecommendation == null)
{
var errorMessage = $"{deployedApplication.StackName} already exists as a Cloudformation stack but a compatible recommendation used to perform a re-deployment was not found.";
throw new FailedToFindCompatibleRecipeException(errorMessage);
throw new FailedToFindCompatibleRecipeException(DeployToolErrorCode.CompatibleRecommendationForRedeploymentNotFound, errorMessage);
}
if (!string.IsNullOrEmpty(deploymentSettingRecipeId) && !string.Equals(deploymentSettingRecipeId, selectedRecommendation.Recipe.Id, StringComparison.InvariantCultureIgnoreCase))
{
Expand All @@ -286,7 +286,7 @@ private async Task<Recommendation> GetSelectedRecommendationFromPreviousDeployme
{
errorMessage += Environment.NewLine + $"The original deployment recipe ID was {deployedApplication.RecipeId} and the current deployment recipe ID is {deploymentSettingRecipeId}";
}
throw new InvalidUserDeploymentSettingsException(errorMessage.Trim());
throw new InvalidUserDeploymentSettingsException(DeployToolErrorCode.StackCreatedFromDifferentDeploymentRecommendation, errorMessage.Trim());
}

selectedRecommendation = selectedRecommendation.ApplyPreviousSettings(existingCloudApplicationMetadata.Settings);
Expand Down Expand Up @@ -351,7 +351,7 @@ private async Task<string> GetDeploymentProjectRecipeId(string deploymentProject
}
catch (Exception ex)
{
throw new FailedToFindDeploymentProjectRecipeIdException($"Failed to find a recipe ID for the deployment project located at {deploymentProjectPath}", ex);
throw new FailedToFindDeploymentProjectRecipeIdException(DeployToolErrorCode.FailedToFindDeploymentProjectRecipeId, $"Failed to find a recipe ID for the deployment project located at {deploymentProjectPath}", ex);
}
}

Expand Down Expand Up @@ -389,13 +389,13 @@ private void ConfigureDeploymentFromConfigFile(Recommendation recommendation, Us
settingValue = double.Parse(optionSettingValue);
break;
default:
throw new InvalidOverrideValueException($"Invalid value {optionSettingValue} for option setting item {optionSettingJsonPath}");
throw new InvalidOverrideValueException(DeployToolErrorCode.InvalidValueForOptionSettingItem, $"Invalid value {optionSettingValue} for option setting item {optionSettingJsonPath}");
}
}
catch (Exception exception)
{
_toolInteractiveService.WriteDebugLine(exception.PrettyPrint());
throw new InvalidOverrideValueException($"Invalid value {optionSettingValue} for option setting item {optionSettingJsonPath}");
throw new InvalidOverrideValueException(DeployToolErrorCode.InvalidValueForOptionSettingItem, $"Invalid value {optionSettingValue} for option setting item {optionSettingJsonPath}");
}

optionSetting.SetValueOverride(settingValue);
Expand Down Expand Up @@ -423,7 +423,7 @@ private void ConfigureDeploymentFromConfigFile(Recommendation recommendation, Us
{
errorMessage += result.ValidationFailedMessage + Environment.NewLine;
}
throw new InvalidUserDeploymentSettingsException(errorMessage.Trim());
throw new InvalidUserDeploymentSettingsException(DeployToolErrorCode.DeploymentConfigurationNeedsAdjusting, errorMessage.Trim());
}

private void SetDeploymentBundleOptionSetting(Recommendation recommendation, string optionSettingId, object settingValue)
Expand Down Expand Up @@ -459,7 +459,7 @@ private string GetCloudApplicationName(string? stackName, UserDeploymentSettings
return stackName;

PrintInvalidStackNameMessage();
throw new InvalidCliArgumentException("Found invalid CLI arguments");
throw new InvalidCliArgumentException(DeployToolErrorCode.InvalidCliArguments, "Found invalid CLI arguments");
}

if (!string.IsNullOrEmpty(userDeploymentSettings?.StackName))
Expand All @@ -468,14 +468,14 @@ private string GetCloudApplicationName(string? stackName, UserDeploymentSettings
return userDeploymentSettings.StackName;

PrintInvalidStackNameMessage();
throw new InvalidUserDeploymentSettingsException("Please provide a valid stack name and try again.");
throw new InvalidUserDeploymentSettingsException(DeployToolErrorCode.UserDeploymentInvalidStackName, "Please provide a valid stack name and try again.");
}

if (_toolInteractiveService.DisableInteractive)
{
var message = "The \"--silent\" CLI argument can only be used if a CDK stack name is provided either via the CLI argument \"--stack-name\" or through a deployment-settings file. " +
"Please provide a stack name and try again";
throw new InvalidCliArgumentException(message);
throw new InvalidCliArgumentException(DeployToolErrorCode.SilentArgumentNeedsStackNameArgument, message);
}
return AskUserForCloudApplicationName(_session.ProjectDefinition, deployedApplications);
}
Expand All @@ -498,15 +498,15 @@ private Recommendation GetSelectedRecommendation(UserDeploymentSettings? userDep
"deployement-settings file or if a path to a custom CDK deployment project is provided via the '--deployment-project' CLI argument." +
$"{Environment.NewLine}Please provide a deployment recipe and try again";

throw new InvalidCliArgumentException(message);
throw new InvalidCliArgumentException(DeployToolErrorCode.SilentArgumentNeedsDeploymentRecipe, message);
}
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)}'.");
throw new InvalidUserDeploymentSettingsException(DeployToolErrorCode.InvalidPropertyValueForUserDeployment, $"The user deployment settings provided contains an invalid value for the property '{nameof(userDeploymentSettings.RecipeId)}'.");
}

_toolInteractiveService.WriteLine();
Expand Down Expand Up @@ -602,7 +602,7 @@ private async Task CreateDeploymentBundle(Orchestrator orchestrator, Recommendat
var errorMessage = "Failed to build Docker Image." + Environment.NewLine;
errorMessage += "Docker builds usually fail due to executing them from a working directory that is incompatible with the Dockerfile." + Environment.NewLine;
errorMessage += "Specify a valid Docker execution directory as part of the deployment settings file and try again.";
throw new DockerBuildFailedException(errorMessage);
throw new DockerBuildFailedException(DeployToolErrorCode.DockerBuildFailed, errorMessage);
}

_toolInteractiveService.WriteLine(string.Empty);
Expand All @@ -622,15 +622,15 @@ private async Task CreateDeploymentBundle(Orchestrator orchestrator, Recommendat
}
else
{
throw new FailedToCreateDeploymentBundleException("Failed to create a deployment bundle");
throw new FailedToCreateDeploymentBundleException(DeployToolErrorCode.FailedToCreateContainerDeploymentBundle, "Failed to create a deployment bundle");
}
}
}
else if (selectedRecommendation.Recipe.DeploymentBundle == DeploymentBundleTypes.DotnetPublishZipFile)
{
var dotnetPublishDeploymentBundleResult = await orchestrator.CreateDotnetPublishDeploymentBundle(selectedRecommendation);
if (!dotnetPublishDeploymentBundleResult)
throw new FailedToCreateDeploymentBundleException("Failed to create a deployment bundle");
throw new FailedToCreateDeploymentBundleException(DeployToolErrorCode.FailedToCreateDotnetPublishDeploymentBundle, "Failed to create a deployment bundle");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task ExecuteAsync(string saveCdkDirectoryPath, string projectDispla
if (newDirectoryCreated)
_directoryManager.Delete(saveCdkDirectoryPath);
errorMessage = $"Failed to generate deployment project.{Environment.NewLine}{errorMessage}";
throw new InvalidSaveDirectoryForCdkProject(errorMessage.Trim());
throw new InvalidSaveDirectoryForCdkProject(DeployToolErrorCode.InvalidSaveDirectoryForCdkProject, errorMessage.Trim());
}

var directoryUnderSourceControl = await IsDirectoryUnderSourceControl(saveCdkDirectoryPath);
Expand Down Expand Up @@ -122,7 +122,7 @@ private async Task<List<Recommendation>> GenerateRecommendationsToSaveDeployment
var recommendations = await orchestrator.GenerateRecommendationsToSaveDeploymentProject();
if (recommendations.Count == 0)
{
throw new FailedToGenerateAnyRecommendations("The project you are trying to deploy is currently not supported.");
throw new FailedToGenerateAnyRecommendations(DeployToolErrorCode.DeploymentProjectNotSupported, "The project you are trying to deploy is currently not supported.");
}
return recommendations;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AWS.Deploy.CLI/Commands/ServerModeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ServerModeCommand(IToolInteractiveService interactiveService, int port, i
IEncryptionProvider encryptionProvider = CreateEncryptionProvider();

if (IsPortInUse(_port))
throw new TcpPortInUseException("The port you have selected is currently in use by another process.");
throw new TcpPortInUseException(DeployToolErrorCode.TcpPortInUse, "The port you have selected is currently in use by another process.");

var url = $"http://localhost:{_port}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
return new BeanstalkApplicationTypeHintResponse(
userResponse.CreateNew,
userResponse.SelectedOption?.ApplicationName ?? userResponse.NewName
?? throw new UserPromptForNameReturnedNullException("The user response for a new application name was null.")
?? throw new UserPromptForNameReturnedNullException(DeployToolErrorCode.BeanstalkAppPromptForNameReturnedNull, "The user response for a new application name was null.")
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
askNewName: true,
defaultNewName: currentValue.ToString() ?? "");
return userResponse.SelectedOption ?? userResponse.NewName
?? throw new UserPromptForNameReturnedNullException("The user response for a new environment name was null.");
?? throw new UserPromptForNameReturnedNullException(DeployToolErrorCode.BeanstalkEnvPromptForNameReturnedNull, "The user response for a new environment name was null.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void OverrideValue(Recommendation recommendation, string dockerBuildArgs)
{
var resultString = ValidateBuildArgs(dockerBuildArgs);
if (!string.IsNullOrEmpty(resultString))
throw new InvalidOverrideValueException(resultString);
throw new InvalidOverrideValueException(DeployToolErrorCode.InvalidDockerBuildArgs, resultString);
recommendation.DeploymentBundle.DockerBuildArgs = dockerBuildArgs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void OverrideValue(Recommendation recommendation, string executionDirecto
{
var resultString = ValidateExecutionDirectory(executionDirectory);
if (!string.IsNullOrEmpty(resultString))
throw new InvalidOverrideValueException(resultString);
throw new InvalidOverrideValueException(DeployToolErrorCode.InvalidDockerExecutionDirectory, resultString);
recommendation.DeploymentBundle.DockerExecutionDirectory = executionDirectory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void OverrideValue(Recommendation recommendation, string publishArgs)
{
var resultString = ValidateDotnetPublishArgs(publishArgs);
if (!string.IsNullOrEmpty(resultString))
throw new InvalidOverrideValueException(resultString);
throw new InvalidOverrideValueException(DeployToolErrorCode.InvalidDotnetPublishArgs, resultString);
recommendation.DeploymentBundle.DotnetPublishAdditionalBuildArguments = publishArgs.Replace("\"", "\"\"");
}

Expand Down
2 changes: 1 addition & 1 deletion src/AWS.Deploy.CLI/Commands/TypeHints/EC2KeyPairCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
else
{
settingValue = userResponse.SelectedOption?.KeyName ?? userResponse.NewName ??
throw new UserPromptForNameReturnedNullException("The user prompt for a new EC2 Key Pair name was null or empty.");
throw new UserPromptForNameReturnedNullException(DeployToolErrorCode.EC2KeyPairPromptForNameReturnedNull, "The user prompt for a new EC2 Key Pair name was null or empty.");
}

if (userResponse.CreateNew && !string.IsNullOrEmpty(userResponse.NewName))
Expand Down
Loading

0 comments on commit 6c508ac

Please sign in to comment.