Skip to content

Commit

Permalink
chore: update Newtonsoft.Json version
Browse files Browse the repository at this point in the history
  • Loading branch information
philasmar committed Jun 23, 2022
1 parent b8e73ab commit 5e69f8f
Show file tree
Hide file tree
Showing 23 changed files with 47 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
idSelector: app => app.ApplicationName,
displaySelector: app => app.ApplicationName,
defaultSelector: app => app.ApplicationName.Equals(currentTypeHintResponse?.ApplicationName),
defaultNewName: currentTypeHintResponse.ApplicationName ?? String.Empty)
defaultNewName: currentTypeHintResponse?.ApplicationName ?? string.Empty)
{
AskNewName = true,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
idSelector: env => env.EnvironmentName,
displaySelector: env => env.EnvironmentName,
defaultSelector: app => app.EnvironmentName.Equals(currentTypeHintResponse?.EnvironmentName),
defaultNewName: currentTypeHintResponse.EnvironmentName)
defaultNewName: currentTypeHintResponse?.EnvironmentName ?? string.Empty)
{
AskNewName = true,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Task<object> Execute(Recommendation recommendation, OptionSettingItem opt
var settingValue = _consoleUtilities
.AskUserForValue(
string.Empty,
_optionSettingHandler.GetOptionSettingValue<string>(recommendation, optionSetting),
_optionSettingHandler.GetOptionSettingValue<string>(recommendation, optionSetting) ?? string.Empty,
allowEmpty: true,
resetValue: _optionSettingHandler.GetOptionSettingDefaultValue<string>(recommendation, optionSetting) ?? "",
validators: async buildArgs => await ValidateBuildArgs(buildArgs, recommendation, optionSetting))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Task<object> Execute(Recommendation recommendation, OptionSettingItem opt
var settingValue = _consoleUtilities
.AskUserForValue(
string.Empty,
_optionSettingHandler.GetOptionSettingValue<string>(recommendation, optionSetting),
_optionSettingHandler.GetOptionSettingValue<string>(recommendation, optionSetting) ?? string.Empty,
allowEmpty: true,
resetValue: _optionSettingHandler.GetOptionSettingDefaultValue<string>(recommendation, optionSetting) ?? "",
validators: async executionDirectory => await ValidateExecutionDirectory(executionDirectory, recommendation, optionSetting));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Task<object> Execute(Recommendation recommendation, OptionSettingItem opt
var settingValue = _consoleUtilities
.AskUserForValue(
string.Empty,
_optionSettingHandler.GetOptionSettingValue<string>(recommendation, optionSetting),
_optionSettingHandler.GetOptionSettingValue<string>(recommendation, optionSetting) ?? string.Empty,
allowEmpty: true,
resetValue: _optionSettingHandler.GetOptionSettingDefaultValue<string>(recommendation, optionSetting) ?? "",
validators: async publishArgs => await ValidateDotnetPublishArgs(publishArgs, recommendation, optionSetting))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Task<object> Execute(Recommendation recommendation, OptionSettingItem opt
var settingValue =
_consoleUtilities.AskUserForValue(
string.Empty,
_optionSettingHandler.GetOptionSettingValue<string>(recommendation, optionSetting),
_optionSettingHandler.GetOptionSettingValue<string>(recommendation, optionSetting) ?? string.Empty,
allowEmpty: false,
resetValue: _optionSettingHandler.GetOptionSettingDefaultValue<string>(recommendation, optionSetting) ?? "");
recommendation.DeploymentBundle.DotnetPublishBuildConfiguration = settingValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
idSelector: rep => rep.RepositoryName,
displaySelector: rep => rep.RepositoryName,
defaultSelector: rep => rep.RepositoryName.Equals(currentRepositoryName),
defaultNewName: currentRepositoryName)
defaultNewName: currentRepositoryName ?? string.Empty)
{
AskNewName = true,
};
Expand Down
2 changes: 1 addition & 1 deletion src/AWS.Deploy.CLI/Commands/TypeHints/ECSClusterCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
idSelector: cluster => cluster.ClusterArn,
displaySelector: cluster => cluster.ClusterName,
defaultSelector: cluster => cluster.ClusterArn.Equals(currentTypeHintResponse?.ClusterArn),
defaultNewName: currentTypeHintResponse.NewClusterName)
defaultNewName: currentTypeHintResponse?.NewClusterName ?? string.Empty)
{
AskNewName = true
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
idSelector: vpcConnector => vpcConnector.VpcConnectorArn,
displaySelector: vpcConnector => vpcConnector.VpcConnectorName,
defaultSelector: vpcConnector => vpcConnector.VpcConnectorArn.Equals(currentVpcConnector),
defaultNewName: currentVpcConnector)
defaultNewName: currentVpcConnector ?? string.Empty)
{
CanBeEmpty = true,
CreateNew = false
Expand Down
2 changes: 1 addition & 1 deletion src/AWS.Deploy.CLI/Commands/TypeHints/FilePathCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Task<object> Execute(Recommendation recommendation, OptionSettingItem opt
var userFilePath = _consoleUtilities
.AskUserForValue(
string.Empty,
_optionSettingHandler.GetOptionSettingValue<string>(recommendation, optionSetting),
_optionSettingHandler.GetOptionSettingValue<string>(recommendation, optionSetting) ?? string.Empty,
allowEmpty: typeHintData?.AllowEmpty ?? true,
resetValue: _optionSettingHandler.GetOptionSettingDefaultValue<string>(recommendation, optionSetting) ?? "") ;

Expand Down
2 changes: 1 addition & 1 deletion src/AWS.Deploy.CLI/Commands/TypeHints/IAMRoleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task<object> Execute(Recommendation recommendation, OptionSettingIt
var userInputConfiguration = new UserInputConfiguration<Role>(
idSelector: role => role.Arn,
displaySelector: role => role.RoleName,
defaultSelector: role => currentTypeHintResponse.RoleArn?.Equals(role.Arn) ?? false);
defaultSelector: role => currentTypeHintResponse?.RoleArn?.Equals(role.Arn) ?? false);

var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(existingRoles ,"Select an IAM role", userInputConfiguration);

Expand Down
2 changes: 1 addition & 1 deletion src/AWS.Deploy.Common/AWS.Deploy.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="AWSSDK.SimpleSystemsManagement" Version="3.7.16" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.7.2.53" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.1.25" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="AWSSDK.ElasticBeanstalk" Version="3.7.0.45" />
<PackageReference Include="AWSSDK.ElasticLoadBalancingV2" Version="3.7.0.48" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public async Task<List<string>> GetRecipeDefinitionPaths(string targetApplicatio
private async Task<DeploymentManifestModel> ReadManifestFile(string filePath)
{
var manifestFilejsonString = await _fileManager.ReadAllTextAsync(filePath);
return JsonConvert.DeserializeObject<DeploymentManifestModel>(manifestFilejsonString);
return JsonConvert.DeserializeObject<DeploymentManifestModel>(manifestFilejsonString) ??
throw new FailedToDeserializeException(DeployToolErrorCode.InvalidDeploymentManifestModel, "The deployment manifest file is invalid.");
}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/AWS.Deploy.Common/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ public enum DeployToolErrorCode
SelectedValueIsNotAllowed = 10009600,
MissingValidatorConfiguration = 10009700,
InvalidFilePath = 10009800,
InvalidDeployToolWorkspace = 10009900
InvalidDeployToolWorkspace = 10009900,
InvalidDeploymentManifestModel = 10010000,
FailedToCreateDeepCopy = 10010100,
FailedToGetOptionSettingValue = 10010200,
ECRRepositoryNameIsNull = 10010300
}

public class ProjectFileNotFoundException : DeployToolException
Expand Down
3 changes: 2 additions & 1 deletion src/AWS.Deploy.Common/Extensions/GenericExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public static class GenericExtensions
public static T DeepCopy<T>(this T obj)
{
var serializedObject = JsonConvert.SerializeObject(obj);
return JsonConvert.DeserializeObject<T>(serializedObject);
return JsonConvert.DeserializeObject<T>(serializedObject) ??
throw new FailedToDeserializeException(DeployToolErrorCode.FailedToCreateDeepCopy, "Failed to create a deep copy.");
}

public static bool TryDeserialize<T>(this object obj, out T? inputList)
Expand Down
2 changes: 1 addition & 1 deletion src/AWS.Deploy.Common/Recipes/IOptionSettingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface IOptionSettingHandler
/// Retrieve the <see cref="OptionSettingItem"/> value for a specific <see cref="Recommendation"/>
/// This method retrieves the value in a specified type.
/// </summary>
T GetOptionSettingValue<T>(Recommendation recommendation, OptionSettingItem optionSetting);
T? GetOptionSettingValue<T>(Recommendation recommendation, OptionSettingItem optionSetting);

/// <summary>
/// Retrieve the <see cref="OptionSettingItem"/> value for a specific <see cref="Recommendation"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace AWS.Deploy.Common.Recipes
/// <see cref="GetValue{T}"/>, <see cref="GetValue"/> and <see cref="SetValueOverride"/> methods
public partial class OptionSettingItem
{
public T GetValue<T>(IDictionary<string, string> replacementTokens, IDictionary<string, bool>? displayableOptionSettings = null)
public T? GetValue<T>(IDictionary<string, string> replacementTokens, IDictionary<string, bool>? displayableOptionSettings = null)
{
var value = GetValue(replacementTokens, displayableOptionSettings);

Expand Down Expand Up @@ -159,7 +159,7 @@ public async Task SetValue(IOptionSettingHandler optionSettingHandler, object va
var deserialized = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(valueOverride));
foreach (var childOptionSetting in ChildOptionSettings)
{
if (deserialized.TryGetValue(childOptionSetting.Id, out var childValueOverride))
if (deserialized?.TryGetValue(childOptionSetting.Id, out var childValueOverride) ?? false)
{
await optionSettingHandler.SetOptionSettingValue(recommendation, childOptionSetting, childValueOverride, skipValidation: skipValidation);
}
Expand Down
2 changes: 1 addition & 1 deletion src/AWS.Deploy.Common/Recipes/OptionSettingItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IOptionSettingItem
/// <summary>
/// Retrieve the value of an <see cref="OptionSettingItem"/> as a specified type.
/// </summary>
T GetValue<T>(IDictionary<string, string> replacementTokens, IDictionary<string, bool>? displayableOptionSettings = null);
T? GetValue<T>(IDictionary<string, string> replacementTokens, IDictionary<string, bool>? displayableOptionSettings = null);

/// <summary>
/// Retrieve the value of an <see cref="OptionSettingItem"/> as an object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ private static IEnumerable<string> BuildMemoryArray(int start, int end, int incr
/// <inheritdoc cref="FargateTaskCpuMemorySizeValidator"/>
public Task<ValidationResult> Validate(Recommendation recommendation, IDeployToolValidationContext deployValidationContext)
{
string cpu;
string memory;
string? cpu;
string? memory;

try
{
Expand All @@ -76,6 +76,11 @@ public Task<ValidationResult> Validate(Recommendation recommendation, IDeployToo
"as part of of the ECS Fargate deployment configuration. Please provide a valid value and try again."));
}

if (cpu == null)
return ValidationResult.FailedAsync("Task CPU is null.");
if (memory == null)
return ValidationResult.FailedAsync("Task Memory is null.");

if (!_cpuMemoryMap.ContainsKey(cpu))
{
// this could happen, but shouldn't.
Expand Down
7 changes: 4 additions & 3 deletions src/AWS.Deploy.Common/UserDeploymentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class UserDeploymentSettings
{
try
{
var userDeploymentSettings = JsonConvert.DeserializeObject<UserDeploymentSettings>(File.ReadAllText(filePath));
var userDeploymentSettings = JsonConvert.DeserializeObject<UserDeploymentSettings>(File.ReadAllText(filePath)) ??
throw new FailedToDeserializeException(DeployToolErrorCode.FailedToDeserializeUserDeploymentFile, "Failed to read user deployment settings file.");
if (userDeploymentSettings.OptionSettingsConfig != null)
userDeploymentSettings.TraverseRootToLeaf(userDeploymentSettings.OptionSettingsConfig.Root);
return userDeploymentSettings;
Expand All @@ -56,7 +57,7 @@ private void TraverseRootToLeaf(JToken node)
{
if (!string.IsNullOrEmpty(node.Path) && node.Type.ToString().Equals("Array"))
{
var list = node.Values<string>().Select(x => x.ToString()).ToList();
var list = node.Values<string>().Select(x => x?.ToString()).ToList();
LeafOptionSettingItems.Add(node.Path, JsonConvert.SerializeObject(list));
return;
}
Expand All @@ -70,7 +71,7 @@ private void TraverseRootToLeaf(JToken node)
var path = node.Path;
if (path.Contains("['"))
path = path.Substring(2, node.Path.Length - 4);
LeafOptionSettingItems.Add(path, node.Value<string>());
LeafOptionSettingItems.Add(path, node.Value<string>() ?? string.Empty);
return;
}

Expand Down
8 changes: 8 additions & 0 deletions src/AWS.Deploy.Orchestration/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public class DockerTagFailedException : DeployToolException
public DockerTagFailedException(DeployToolErrorCode errorCode, string message, int processExitCode, Exception? innerException = null) : base(errorCode, message, innerException, processExitCode) { }
}

/// <summary>
/// Exception is thrown if ECR repository name is invalid.
/// </summary>
public class InvalidECRRepositoryNameException : DeployToolException
{
public InvalidECRRepositoryNameException(DeployToolErrorCode errorCode, string message, Exception? innerException = null) : base(errorCode, message, innerException) { }
}

/// <summary>
/// Exception is thrown if docker push attempt failed
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/AWS.Deploy.Orchestration/OptionSettingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public OptionSettingItem GetOptionSetting(RecipeDefinition recipe, string? jsonP
/// <summary>
/// Retrieves the value of the Option Setting Item in a given recommendation.
/// </summary>
public T GetOptionSettingValue<T>(Recommendation recommendation, OptionSettingItem optionSetting)
public T? GetOptionSettingValue<T>(Recommendation recommendation, OptionSettingItem optionSetting)
{
var displayableOptionSettings = new Dictionary<string, bool>();
if (optionSetting.Type == OptionSettingValueType.Object)
Expand Down
2 changes: 2 additions & 0 deletions src/AWS.Deploy.Orchestration/Orchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ private async Task CreateContainerDeploymentBundle(CloudApplication cloudApplica
// Read this from the OptionSetting instead of recommendation.DeploymentBundle.
// When its value comes from a replacement token, it wouldn't have been set back to the DeploymentBundle
var respositoryName = _optionSettingHandler.GetOptionSettingValue<string>(recommendation, _optionSettingHandler.GetOptionSetting(recommendation, Constants.Docker.ECRRepositoryNameOptionId));
if (respositoryName == null)
throw new InvalidECRRepositoryNameException(DeployToolErrorCode.ECRRepositoryNameIsNull, "The ECR Repository Name is null.");

string imageTag;
try
Expand Down

0 comments on commit 5e69f8f

Please sign in to comment.