Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .autover/changes/7107587d-3fa8-4094-aa23-7b1d1f92b562.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"Projects": [
{
"Name": "Amazon.ECS.Tools",
"Type": "Major",
"ChangelogMessages": [
"Updated to V4 of the AWS SDK for .NET",
"Updated the minimum requirement from .NET Core 3.1 to .NET 6"
]
},
{
"Name": "Amazon.ElasticBeanstalk.Tools",
"Type": "Major",
"ChangelogMessages": [
"Updated to V4 of the AWS SDK for .NET",
"Updated the minimum requirement from .NET Core 3.1 to .NET 6"
]
},
{
"Name": "Amazon.Lambda.Tools",
"Type": "Major",
"ChangelogMessages": [
"Updated to V4 of the AWS SDK for .NET",
"Updated the minimum requirement from .NET Core 3.1 to .NET 6",
"Fixed \"The image manifest or layer media type for the source image is not supported.\" issue when container image was built for a Lambda function by adding the \"--provenance=false\" switch for the docker buildx command"
]
}

]
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\buildtools\common.props" />
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<!--
This is explicitly set to 7.3 to match what the AWS VS Toolkit uses. This is required because
the source code here is also copied into the AWS VS Toolkit.
-->
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.Core" Version="3.7.303.20" />
<PackageReference Include="AWSSDK.ECR" Version="3.7.301.75" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.301.6" />
<PackageReference Include="AWSSDK.S3" Version="3.7.307.21" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.300.81" />
<PackageReference Include="AWSSDK.SSO" Version="3.7.300.80" />
<PackageReference Include="AWSSDK.SSOOIDC" Version="3.7.301.75" />
<PackageReference Include="AWSSDK.Core" Version="4.0.0.26" />
<PackageReference Include="AWSSDK.ECR" Version="4.0.4.1" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="4.0.3.2" />
<PackageReference Include="AWSSDK.S3" Version="4.0.6.13" />
<PackageReference Include="AWSSDK.SecurityToken" Version="4.0.2.1" />
<PackageReference Include="AWSSDK.SSO" Version="4.0.1.1" />
<PackageReference Include="AWSSDK.SSOOIDC" Version="4.0.1.1" />
</ItemGroup>
<PropertyGroup>
<NoWarn>1701;1702;1705;1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1701;1702;1705;1591;NETSDK1138</NoWarn>
</PropertyGroup>

</Project>
47 changes: 24 additions & 23 deletions src/Amazon.Common.DotNetCli.Tools/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using ThirdParty.Json.LitJson;

using Amazon.ECR;
using Amazon.IdentityManagement;
using Amazon.IdentityManagement.Model;
using Amazon.S3;
using Amazon.SecurityToken;
using Amazon.Runtime.Credentials;

namespace Amazon.Common.DotNetCli.Tools.Commands
{
Expand All @@ -36,7 +37,7 @@ public BaseCommand(IToolLogger logger, string workingDirectory)
public BaseCommand(IToolLogger logger, string workingDirectory, IList<CommandOption> possibleOptions, string[] args)
: this(logger, workingDirectory)
{
args = args ?? new string[0];
args = args ?? Array.Empty<string>();
this.OriginalCommandLineArguments = args;
var values = CommandLineParser.ParseArguments(possibleOptions, args);
ParseCommandArguments(values);
Expand Down Expand Up @@ -250,12 +251,12 @@ protected AWSCredentials DetermineAWSCredentials()
var chain = new CredentialProfileStoreChain(this.ProfileLocation);
if (!chain.TryGetAWSCredentials(profile, out this._resolvedCredentials))
{
this._resolvedCredentials = FallbackCredentialsFactory.GetCredentials();
this._resolvedCredentials = DefaultAWSCredentialsIdentityResolver.GetCredentials();
}
}
else
{
this._resolvedCredentials = FallbackCredentialsFactory.GetCredentials();
this._resolvedCredentials = DefaultAWSCredentialsIdentityResolver.GetCredentials();
}

if(this._resolvedCredentials is AssumeRoleAWSCredentials)
Expand Down Expand Up @@ -384,21 +385,23 @@ public string GetRoleValueOrDefault(string propertyValue, CommandOption option,
}

/// <summary>
/// Complex parameters are formatted as a JSON string. This method parses the string into the JsonData object
/// Complex parameters are formatted as a JSON string. This method parses the string into the JsonElement object
/// </summary>
/// <param name="propertyValue"></param>
/// <param name="option"></param>
/// <returns></returns>
public JsonData GetJsonValueOrDefault(string propertyValue, CommandOption option)
public JsonElement? GetJsonValueOrDefault(string propertyValue, CommandOption option)
{
string jsonContent = GetStringValueOrDefault(propertyValue, option, false);
if (string.IsNullOrWhiteSpace(jsonContent))
return null;

try
{
var data = JsonMapper.ToObject(jsonContent);
return data;
using (JsonDocument doc = JsonDocument.Parse(jsonContent))
{
return doc.RootElement.Clone();
}
}
catch(Exception e)
{
Expand Down Expand Up @@ -697,7 +700,7 @@ protected string PromptForValue(CommandOption option)
return cachedValue;
}

string input = null;
string input;


Console.Out.WriteLine($"Enter {option.Name}: ({option.Description})");
Expand Down Expand Up @@ -838,29 +841,27 @@ protected void SaveConfigFile()
{
try
{
JsonData data;
var data = new Dictionary<string, object>();
if (File.Exists(this.DefaultConfig.SourceFile))
{
data = JsonMapper.ToObject(File.ReadAllText(this.DefaultConfig.SourceFile));
}
else
{
data = new JsonData();
string existingJson = File.ReadAllText(this.DefaultConfig.SourceFile);
using (JsonDocument doc = JsonDocument.Parse(existingJson))
{
foreach (JsonProperty prop in doc.RootElement.EnumerateObject())
{
data[prop.Name] = prop.Value.GetJsonValue();
}
}
}

data.SetIfNotNull(CommonDefinedCommandOptions.ARGUMENT_AWS_REGION.ConfigFileKey, this.GetStringValueOrDefault(this.Region, CommonDefinedCommandOptions.ARGUMENT_AWS_REGION, false));
data.SetIfNotNull(CommonDefinedCommandOptions.ARGUMENT_AWS_PROFILE.ConfigFileKey, this.GetStringValueOrDefault(this.Profile, CommonDefinedCommandOptions.ARGUMENT_AWS_PROFILE, false));
data.SetIfNotNull(CommonDefinedCommandOptions.ARGUMENT_AWS_PROFILE_LOCATION.ConfigFileKey, this.GetStringValueOrDefault(this.ProfileLocation, CommonDefinedCommandOptions.ARGUMENT_AWS_PROFILE_LOCATION, false));


SaveConfigFile(data);

StringBuilder sb = new StringBuilder();
JsonWriter writer = new JsonWriter(sb);
writer.PrettyPrint = true;
JsonMapper.ToJson(data, writer);

var json = sb.ToString();
var options = new JsonSerializerOptions { WriteIndented = true };
var json = JsonSerializer.Serialize(data, options);
File.WriteAllText(this.DefaultConfig.SourceFile, json);
this.Logger?.WriteLine($"Config settings saved to {this.DefaultConfig.SourceFile}");
}
Expand All @@ -870,7 +871,7 @@ protected void SaveConfigFile()
}
}

protected abstract void SaveConfigFile(JsonData data);
protected abstract void SaveConfigFile(Dictionary<string, object> data);

public bool ConfirmDeletion(string resource)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using Amazon.ECR.Model;
using Amazon.ECR;
using ThirdParty.Json.LitJson;
using System.IO;
using Amazon.Common.DotNetCli.Tools.Options;
using Amazon.Common.DotNetCli.Tools;
Expand Down Expand Up @@ -338,7 +337,7 @@ private async Task<Repository> SetupECRRepository(string ecrRepositoryName)
}

Repository repository;
if (describeResponse != null && describeResponse.Repositories.Count == 1)
if (describeResponse != null && describeResponse.Repositories != null && describeResponse.Repositories.Count == 1)
{
this.Logger?.WriteLine($"Found existing ECR Repository {ecrRepositoryName}");
repository = describeResponse.Repositories[0];
Expand Down Expand Up @@ -367,6 +366,11 @@ private async Task InitiateDockerLogin(DockerCLIWrapper dockerCLI)
this.Logger?.WriteLine("Fetching ECR authorization token to use to login with the docker CLI");
var response = await this.ECRClient.GetAuthorizationTokenAsync(new GetAuthorizationTokenRequest());

if (response.AuthorizationData == null || response.AuthorizationData.Count == 0)
{
throw new ToolsException("No authorization data returned from ECR", ToolsException.CommonErrorCode.GetECRAuthTokens);
}

var authTokenBytes = Convert.FromBase64String(response.AuthorizationData[0].AuthorizationToken);
var authToken = Encoding.UTF8.GetString(authTokenBytes);
var decodedTokens = authToken.Split(':');
Expand All @@ -387,7 +391,7 @@ private async Task InitiateDockerLogin(DockerCLIWrapper dockerCLI)
}
}

protected override void SaveConfigFile(JsonData data)
protected override void SaveConfigFile(Dictionary<string, object> data)
{
this.PushDockerImageProperties.PersistSettings(this, data);
}
Expand Down Expand Up @@ -490,7 +494,7 @@ public void ParseCommandArguments(CommandOptions values)
}


public void PersistSettings(BaseCommand<TDefaultConfig> command, JsonData data)
public void PersistSettings(BaseCommand<TDefaultConfig> command, Dictionary<string, object> data)
{
data.SetIfNotNull(CommonDefinedCommandOptions.ARGUMENT_CONFIGURATION.ConfigFileKey, command.GetStringValueOrDefault(this.Configuration, CommonDefinedCommandOptions.ARGUMENT_CONFIGURATION, false));
data.SetIfNotNull(CommonDefinedCommandOptions.ARGUMENT_FRAMEWORK.ConfigFileKey, command.GetStringValueOrDefault(this.TargetFramework, CommonDefinedCommandOptions.ARGUMENT_FRAMEWORK, false));
Expand Down
Loading
Loading