Skip to content

Commit

Permalink
feat: enable nullability and set C# version to 9
Browse files Browse the repository at this point in the history
  • Loading branch information
philasmar committed May 14, 2021
1 parent ad0f0f6 commit a830854
Show file tree
Hide file tree
Showing 117 changed files with 1,163 additions and 533 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ $RECYCLE.BIN/
##
## Visual Studio Code
##
.vscode/
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
Expand Down
8 changes: 4 additions & 4 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);
string ResolveAWSRegion(string region, string? lastRegionUsed);
}

public class AWSUtilities : IAWSUtilities
Expand All @@ -29,7 +29,7 @@ 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)
{


Expand Down Expand Up @@ -113,7 +113,7 @@ private async Task<bool> CanLoadCredentials(AWSCredentials credentials)
}
}

public string ResolveAWSRegion(string region, string lastRegionUsed)
public string ResolveAWSRegion(string region, string? lastRegionUsed)
{
if (!string.IsNullOrEmpty(region))
{
Expand Down
14 changes: 7 additions & 7 deletions src/AWS.Deploy.CLI/Commands/CommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ private Command BuildDeployCommand()
var callerIdentity = await _awsResourceQueryer.GetCallerIdentity();
var session = new OrchestratorSession
var session = new OrchestratorSession(
projectDefinition,
awsCredentials,
awsRegion,
callerIdentity.Account)
{
AWSProfileName = profile,
AWSCredentials = awsCredentials,
AWSRegion = awsRegion,
AWSAccountId = callerIdentity.Account,
ProjectDefinition = projectDefinition,
SystemCapabilities = systemCapabilities
SystemCapabilities = systemCapabilities,
AWSProfileName = profile
};
var dockerEngine = new DockerEngine.DockerEngine(projectDefinition);
Expand Down
6 changes: 3 additions & 3 deletions src/AWS.Deploy.CLI/Commands/DeleteDeploymentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ private async Task WaitForStackDelete(string stackName)
throw new FailedToDeleteException($"Failed to delete {stackName} stack: {stack.StackStatus}");
}

private async Task<Stack> StabilizeStack(string stackName)
private async Task<Stack?> StabilizeStack(string stackName)
{
Stack stack;
Stack? stack;
do
{
stack = await GetStackAsync(stackName);
Expand All @@ -134,7 +134,7 @@ private async Task<Stack> StabilizeStack(string stackName)
return stack;
}

private async Task<Stack> GetStackAsync(string stackName)
private async Task<Stack?> GetStackAsync(string stackName)
{
try
{
Expand Down
39 changes: 20 additions & 19 deletions src/AWS.Deploy.CLI/Commands/DeployCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public async Task ExecuteAsync(string stackName, bool saveCdkProject)

var deployedApplication = deployedApplications.FirstOrDefault(x => string.Equals(x.Name, cloudApplicationName));

Recommendation selectedRecommendation = null;
Recommendation? selectedRecommendation = null;

_toolInteractiveService.WriteLine();

Expand Down Expand Up @@ -148,6 +148,9 @@ public async Task ExecuteAsync(string stackName, bool saveCdkProject)
// Apply the user enter project name to the recommendation so that any default settings based on project name are applied.
selectedRecommendation.OverrideProjectName(cloudApplicationName);

if (_session.SystemCapabilities == null)
throw new SystemCapabilitiesNotProvidedException("The system capabilities were not provided.");

var systemCapabilities = await _session.SystemCapabilities;
if (selectedRecommendation.Recipe.DeploymentType == DeploymentTypes.CdkProject &&
!systemCapabilities.NodeJsMinVersionInstalled)
Expand All @@ -174,10 +177,7 @@ public async Task ExecuteAsync(string stackName, bool saveCdkProject)

await ConfigureDeployment(selectedRecommendation, configurableOptionSettings, false);

var cloudApplication = new CloudApplication
{
Name = cloudApplicationName
};
var cloudApplication = new CloudApplication(cloudApplicationName, string.Empty);

if (!ConfirmDeployment(selectedRecommendation))
{
Expand Down Expand Up @@ -232,7 +232,8 @@ private string AskUserForCloudApplicationName(ProjectDefinition project, List<Cl
cloudApplicationName = userResponse.SelectedOption ?? userResponse.NewName;
}

if (_cloudApplicationNameGenerator.IsValidName(cloudApplicationName))
if (!string.IsNullOrEmpty(cloudApplicationName) &&
_cloudApplicationNameGenerator.IsValidName(cloudApplicationName))
return cloudApplicationName;

PrintInvalidStackNameMessage();
Expand Down Expand Up @@ -358,7 +359,7 @@ private void DisplayOptionSetting(Recommendation recommendation, OptionSettingIt
{
var value = recommendation.GetOptionSettingValue(optionSetting);

Type typeHintResponseType = null;
Type? typeHintResponseType = null;
if (optionSetting.Type == OptionSettingValueType.Object)
{
var typeHintResponseTypeFullName = $"AWS.Deploy.CLI.TypeHintResponses.{optionSetting.TypeHint}TypeHintResponse";
Expand All @@ -374,14 +375,14 @@ private async Task ConfigureDeployment(Recommendation recommendation, OptionSett
_toolInteractiveService.WriteLine($"{setting.Name}:");
_toolInteractiveService.WriteLine($"{setting.Description}");

var currentValue = recommendation.GetOptionSettingValue(setting);
object settingValue = null;
object currentValue = recommendation.GetOptionSettingValue(setting);
object? settingValue = null;
if (setting.AllowedValues?.Count > 0)
{
var userInputConfig = new UserInputConfiguration<string>
var userInputConfig = new UserInputConfiguration<string>(
x => setting.ValueMapping.ContainsKey(x) ? setting.ValueMapping[x] : x,
x => x.Equals(currentValue))
{
DisplaySelector = x => setting.ValueMapping.ContainsKey(x) ? setting.ValueMapping[x] : x,
DefaultSelector = x => x.Equals(currentValue),
CreateNew = false
};

Expand All @@ -404,7 +405,7 @@ private async Task ConfigureDeployment(Recommendation recommendation, OptionSett
{
case OptionSettingValueType.String:
case OptionSettingValueType.Int:
settingValue = _consoleUtilities.AskUserForValue(string.Empty, currentValue?.ToString(), allowEmpty: true, resetValue: recommendation.GetOptionSettingDefaultValue<string>(setting));
settingValue = _consoleUtilities.AskUserForValue(string.Empty, currentValue.ToString() ?? "", allowEmpty: true, resetValue: recommendation.GetOptionSettingDefaultValue<string>(setting) ?? "");
break;
case OptionSettingValueType.Bool:
var answer = _consoleUtilities.AskYesNoQuestion(string.Empty, recommendation.GetOptionSettingValue(setting).ToString());
Expand Down Expand Up @@ -434,18 +435,18 @@ private async Task ConfigureDeployment(Recommendation recommendation, OptionSett
/// This allows to use a generic implementation to display Object type option setting values without casting the response to
/// the specific TypeHintResponse type.
/// </summary>
private void DisplayValue(Recommendation recommendation, OptionSettingItem optionSetting, int optionSettingNumber, int optionSettingsCount, Type typeHintResponseType, DisplayOptionSettingsMode mode)
private void DisplayValue(Recommendation recommendation, OptionSettingItem optionSetting, int optionSettingNumber, int optionSettingsCount, Type? typeHintResponseType, DisplayOptionSettingsMode mode)
{
object displayValue = null;
Dictionary<string, object> objectValues = null;
object? displayValue = null;
Dictionary<string, object>? objectValues = null;
if (typeHintResponseType != null)
{
var methodInfo = typeof(Recommendation)
.GetMethod(nameof(Recommendation.GetOptionSettingValue), 1, new[] { typeof(OptionSettingItem), typeof(bool) });
.GetMethod(nameof(Recommendation.GetOptionSettingValue), 1, new[] { typeof(OptionSettingItem) });
var genericMethodInfo = methodInfo?.MakeGenericMethod(typeHintResponseType);
var response = genericMethodInfo?.Invoke(recommendation, new object[] { optionSetting, false });
var response = genericMethodInfo?.Invoke(recommendation, new object[] { optionSetting });

displayValue = ((IDisplayable)response)?.ToDisplayString();
displayValue = ((IDisplayable?)response)?.ToDisplayString();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Threading.Tasks;
using Amazon.ElasticBeanstalk.Model;
using AWS.Deploy.CLI.TypeHintResponses;
Expand All @@ -27,21 +28,21 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
var applications = await _awsResourceQueryer.ListOfElasticBeanstalkApplications();
var currentTypeHintResponse = recommendation.GetOptionSettingValue<BeanstalkApplicationTypeHintResponse>(optionSetting);

var userInputConfiguration = new UserInputConfiguration<ApplicationDescription>
var userInputConfiguration = new UserInputConfiguration<ApplicationDescription>(
app => app.ApplicationName,
app => app.ApplicationName.Equals(currentTypeHintResponse?.ApplicationName),
currentTypeHintResponse.ApplicationName)
{
DisplaySelector = app => app.ApplicationName,
DefaultSelector = app => app.ApplicationName.Equals(currentTypeHintResponse?.ApplicationName),
AskNewName = true,
DefaultNewName = currentTypeHintResponse.ApplicationName
};

var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(applications, "Select Elastic Beanstalk application to deploy to:", userInputConfiguration);

return new BeanstalkApplicationTypeHintResponse
{
CreateNew = userResponse.CreateNew,
ApplicationName = userResponse.SelectedOption?.ApplicationName ?? userResponse.NewName
};
return new BeanstalkApplicationTypeHintResponse(
userResponse.CreateNew,
userResponse.SelectedOption?.ApplicationName ?? userResponse.NewName
?? throw new UserPromptForNameReturnedNullException("The user response for a new application name was null.")
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
options: environments.Select(env => env.EnvironmentName),
title: "Select Elastic Beanstalk environment to deploy to:",
askNewName: true,
defaultNewName: currentValue.ToString());
return userResponse.SelectedOption ?? userResponse.NewName;
defaultNewName: currentValue.ToString() ?? "");
return userResponse.SelectedOption ?? userResponse.NewName
?? throw new UserPromptForNameReturnedNullException("The user response for a new environment name was null.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Task<object> Execute(Recommendation recommendation, OptionSettingItem opt
string.Empty,
recommendation.GetOptionSettingValue<string>(optionSetting),
allowEmpty: true,
resetValue: recommendation.GetOptionSettingDefaultValue<string>(optionSetting),
resetValue: recommendation.GetOptionSettingDefaultValue<string>(optionSetting) ?? "",
// validators:
buildArgs => ValidateBuildArgs(buildArgs))
.ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Task<object> Execute(Recommendation recommendation, OptionSettingItem opt
string.Empty,
recommendation.GetOptionSettingValue<string>(optionSetting),
allowEmpty: true,
resetValue: recommendation.GetOptionSettingDefaultValue<string>(optionSetting),
resetValue: recommendation.GetOptionSettingDefaultValue<string>(optionSetting) ?? "",
// validators:
executionDirectory => ValidateExecutionDirectory(executionDirectory));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
var currentValue = recommendation.GetOptionSettingValue(optionSetting);
var platformArns = await _awsResourceQueryer.GetElasticBeanstalkPlatformArns();

var userInputConfiguration = new UserInputConfiguration<PlatformSummary>
var userInputConfiguration = new UserInputConfiguration<PlatformSummary>(
platform => $"{platform.PlatformBranchName} v{platform.PlatformVersion}",
platform => platform.PlatformArn.Equals(currentValue))
{
DisplaySelector = platform => $"{platform.PlatformBranchName} v{platform.PlatformVersion}",
DefaultSelector = platform => platform.PlatformArn.Equals(currentValue),
CreateNew = false
};

var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(platformArns, "Select the Platform to use:", userInputConfiguration);

return userResponse.SelectedOption?.PlatformArn;
return userResponse.SelectedOption?.PlatformArn!;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public Task<object> Execute(Recommendation recommendation, OptionSettingItem opt
var settingValue = _consoleUtilities
.AskUserForValue(
string.Empty,
recommendation.GetOptionSettingValue(optionSetting).ToString(),
recommendation.GetOptionSettingValue<string>(optionSetting),
allowEmpty: true,
resetValue: recommendation.GetOptionSettingDefaultValue<string>(optionSetting),
resetValue: recommendation.GetOptionSettingDefaultValue<string>(optionSetting) ?? "",
// validators:
publishArgs =>
(publishArgs.Contains("-o ") || publishArgs.Contains("--output "))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Task<object> Execute(Recommendation recommendation, OptionSettingItem opt
string.Empty,
recommendation.GetOptionSettingValue<string>(optionSetting),
allowEmpty: false,
resetValue: recommendation.GetOptionSettingDefaultValue<string>(optionSetting));
resetValue: recommendation.GetOptionSettingDefaultValue<string>(optionSetting) ?? "");
recommendation.DeploymentBundle.DotnetPublishBuildConfiguration = settingValue;
return Task.FromResult<object>(settingValue);
}
Expand Down
12 changes: 7 additions & 5 deletions src/AWS.Deploy.CLI/Commands/TypeHints/EC2KeyPairCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
var currentValue = recommendation.GetOptionSettingValue(optionSetting);
var keyPairs = await _awsResourceQueryer.ListOfEC2KeyPairs();

var userInputConfiguration = new UserInputConfiguration<KeyPairInfo>
var userInputConfiguration = new UserInputConfiguration<KeyPairInfo>(
kp => kp.KeyName,
kp => kp.KeyName.Equals(currentValue)
)
{
DisplaySelector = kp => kp.KeyName,
DefaultSelector = kp => kp.KeyName.Equals(currentValue),
AskNewName = true,
EmptyOption = true,
CurrentValue = currentValue
Expand All @@ -49,7 +50,8 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
}
else
{
settingValue = userResponse.SelectedOption?.KeyName ?? userResponse.NewName;
settingValue = userResponse.SelectedOption?.KeyName ?? userResponse.NewName ??
throw new UserPromptForNameReturnedNullException("The user prompt for a new EC2 Key Pair name was null or empty.");
}

if (userResponse.CreateNew && !string.IsNullOrEmpty(userResponse.NewName))
Expand All @@ -73,7 +75,7 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
break;
}

return settingValue;
return settingValue ?? "";
}
}
}
20 changes: 9 additions & 11 deletions src/AWS.Deploy.CLI/Commands/TypeHints/ECSClusterCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
var clusters = await _awsResourceQueryer.ListOfECSClusters();
var currentTypeHintResponse = recommendation.GetOptionSettingValue<ECSClusterTypeHintResponse>(optionSetting);

var userInputConfiguration = new UserInputConfiguration<Cluster>
var userInputConfiguration = new UserInputConfiguration<Cluster>(
cluster => cluster.ClusterName,
cluster => cluster.ClusterArn.Equals(currentTypeHintResponse?.ClusterArn),
currentTypeHintResponse.NewClusterName)
{
DisplaySelector = cluster => cluster.ClusterName,
DefaultSelector = cluster => cluster.ClusterArn.Equals(currentTypeHintResponse?.ClusterArn),
AskNewName = true,
DefaultNewName = currentTypeHintResponse.NewClusterName
AskNewName = true
};

var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(clusters, "Select ECS cluster to deploy to:", userInputConfiguration);

return new ECSClusterTypeHintResponse
{
CreateNew = userResponse.CreateNew,
ClusterArn = userResponse.SelectedOption?.ClusterArn ?? string.Empty,
NewClusterName = userResponse.NewName
};
return new ECSClusterTypeHintResponse(
userResponse.CreateNew,
userResponse.SelectedOption?.ClusterArn ?? string.Empty,
userResponse.NewName ?? string.Empty);
}
}
}
Loading

0 comments on commit a830854

Please sign in to comment.