Skip to content

Commit e22453f

Browse files
committed
Updated to V4 of the AWS SDK for .NET
1 parent 26a5d54 commit e22453f

File tree

76 files changed

+937
-812
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+937
-812
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "Amazon.ECS.Tools",
5+
"Type": "Major",
6+
"ChangelogMessages": [
7+
"Updated to V4 of the AWS SDK for .NET",
8+
"Updated the minimum requirement from .NET Core 3.1 to .NET 6"
9+
]
10+
},
11+
{
12+
"Name": "Amazon.ElasticBeanstalk.Tools",
13+
"Type": "Major",
14+
"ChangelogMessages": [
15+
"Updated to V4 of the AWS SDK for .NET",
16+
"Updated the minimum requirement from .NET Core 3.1 to .NET 6"
17+
]
18+
},
19+
{
20+
"Name": "Amazon.Lambda.Tools",
21+
"Type": "Major",
22+
"ChangelogMessages": [
23+
"Updated to V4 of the AWS SDK for .NET",
24+
"Updated the minimum requirement from .NET Core 3.1 to .NET 6",
25+
"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"
26+
]
27+
}
28+
29+
]
30+
}
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\..\buildtools\common.props" />
33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
4+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
5+
<!--
6+
This is explicitly set to 7.3 to match what the AWS VS Toolkit uses. This is required because
7+
the source code here is also copied into the AWS VS Toolkit.
8+
-->
9+
<LangVersion>7.3</LangVersion>
510
</PropertyGroup>
611
<ItemGroup>
7-
<PackageReference Include="AWSSDK.Core" Version="3.7.303.20" />
8-
<PackageReference Include="AWSSDK.ECR" Version="3.7.301.75" />
9-
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.301.6" />
10-
<PackageReference Include="AWSSDK.S3" Version="3.7.307.21" />
11-
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.300.81" />
12-
<PackageReference Include="AWSSDK.SSO" Version="3.7.300.80" />
13-
<PackageReference Include="AWSSDK.SSOOIDC" Version="3.7.301.75" />
12+
<PackageReference Include="AWSSDK.Core" Version="4.0.0.26" />
13+
<PackageReference Include="AWSSDK.ECR" Version="4.0.4.1" />
14+
<PackageReference Include="AWSSDK.IdentityManagement" Version="4.0.3.2" />
15+
<PackageReference Include="AWSSDK.S3" Version="4.0.6.13" />
16+
<PackageReference Include="AWSSDK.SecurityToken" Version="4.0.2.1" />
17+
<PackageReference Include="AWSSDK.SSO" Version="4.0.1.1" />
18+
<PackageReference Include="AWSSDK.SSOOIDC" Version="4.0.1.1" />
1419
</ItemGroup>
1520
<PropertyGroup>
16-
<NoWarn>1701;1702;1705;1591</NoWarn>
21+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
22+
<NoWarn>1701;1702;1705;1591;NETSDK1138</NoWarn>
1723
</PropertyGroup>
1824

1925
</Project>

src/Amazon.Common.DotNetCli.Tools/Commands/BaseCommand.cs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
using System.Linq;
88
using System.Reflection;
99
using System.Text;
10+
using System.Text.Json;
1011
using System.Threading.Tasks;
11-
using ThirdParty.Json.LitJson;
1212

1313
using Amazon.ECR;
1414
using Amazon.IdentityManagement;
1515
using Amazon.IdentityManagement.Model;
1616
using Amazon.S3;
1717
using Amazon.SecurityToken;
18+
using Amazon.Runtime.Credentials;
1819

1920
namespace Amazon.Common.DotNetCli.Tools.Commands
2021
{
@@ -36,7 +37,7 @@ public BaseCommand(IToolLogger logger, string workingDirectory)
3637
public BaseCommand(IToolLogger logger, string workingDirectory, IList<CommandOption> possibleOptions, string[] args)
3738
: this(logger, workingDirectory)
3839
{
39-
args = args ?? new string[0];
40+
args = args ?? Array.Empty<string>();
4041
this.OriginalCommandLineArguments = args;
4142
var values = CommandLineParser.ParseArguments(possibleOptions, args);
4243
ParseCommandArguments(values);
@@ -250,12 +251,12 @@ protected AWSCredentials DetermineAWSCredentials()
250251
var chain = new CredentialProfileStoreChain(this.ProfileLocation);
251252
if (!chain.TryGetAWSCredentials(profile, out this._resolvedCredentials))
252253
{
253-
this._resolvedCredentials = FallbackCredentialsFactory.GetCredentials();
254+
this._resolvedCredentials = DefaultAWSCredentialsIdentityResolver.GetCredentials();
254255
}
255256
}
256257
else
257258
{
258-
this._resolvedCredentials = FallbackCredentialsFactory.GetCredentials();
259+
this._resolvedCredentials = DefaultAWSCredentialsIdentityResolver.GetCredentials();
259260
}
260261

261262
if(this._resolvedCredentials is AssumeRoleAWSCredentials)
@@ -384,21 +385,23 @@ public string GetRoleValueOrDefault(string propertyValue, CommandOption option,
384385
}
385386

386387
/// <summary>
387-
/// Complex parameters are formatted as a JSON string. This method parses the string into the JsonData object
388+
/// Complex parameters are formatted as a JSON string. This method parses the string into the JsonElement object
388389
/// </summary>
389390
/// <param name="propertyValue"></param>
390391
/// <param name="option"></param>
391392
/// <returns></returns>
392-
public JsonData GetJsonValueOrDefault(string propertyValue, CommandOption option)
393+
public JsonElement? GetJsonValueOrDefault(string propertyValue, CommandOption option)
393394
{
394395
string jsonContent = GetStringValueOrDefault(propertyValue, option, false);
395396
if (string.IsNullOrWhiteSpace(jsonContent))
396397
return null;
397398

398399
try
399400
{
400-
var data = JsonMapper.ToObject(jsonContent);
401-
return data;
401+
using (JsonDocument doc = JsonDocument.Parse(jsonContent))
402+
{
403+
return doc.RootElement.Clone();
404+
}
402405
}
403406
catch(Exception e)
404407
{
@@ -697,7 +700,7 @@ protected string PromptForValue(CommandOption option)
697700
return cachedValue;
698701
}
699702

700-
string input = null;
703+
string input;
701704

702705

703706
Console.Out.WriteLine($"Enter {option.Name}: ({option.Description})");
@@ -838,29 +841,27 @@ protected void SaveConfigFile()
838841
{
839842
try
840843
{
841-
JsonData data;
844+
var data = new Dictionary<string, object>();
842845
if (File.Exists(this.DefaultConfig.SourceFile))
843846
{
844-
data = JsonMapper.ToObject(File.ReadAllText(this.DefaultConfig.SourceFile));
845-
}
846-
else
847-
{
848-
data = new JsonData();
847+
string existingJson = File.ReadAllText(this.DefaultConfig.SourceFile);
848+
using (JsonDocument doc = JsonDocument.Parse(existingJson))
849+
{
850+
foreach (JsonProperty prop in doc.RootElement.EnumerateObject())
851+
{
852+
data[prop.Name] = prop.Value.GetJsonValue();
853+
}
854+
}
849855
}
850856

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

855-
856861
SaveConfigFile(data);
857862

858-
StringBuilder sb = new StringBuilder();
859-
JsonWriter writer = new JsonWriter(sb);
860-
writer.PrettyPrint = true;
861-
JsonMapper.ToJson(data, writer);
862-
863-
var json = sb.ToString();
863+
var options = new JsonSerializerOptions { WriteIndented = true };
864+
var json = JsonSerializer.Serialize(data, options);
864865
File.WriteAllText(this.DefaultConfig.SourceFile, json);
865866
this.Logger?.WriteLine($"Config settings saved to {this.DefaultConfig.SourceFile}");
866867
}
@@ -870,7 +871,7 @@ protected void SaveConfigFile()
870871
}
871872
}
872873

873-
protected abstract void SaveConfigFile(JsonData data);
874+
protected abstract void SaveConfigFile(Dictionary<string, object> data);
874875

875876
public bool ConfirmDeletion(string resource)
876877
{

src/Amazon.Common.DotNetCli.Tools/Commands/BasePushDockerImageCommand.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
using Amazon.ECR.Model;
77
using Amazon.ECR;
8-
using ThirdParty.Json.LitJson;
98
using System.IO;
109
using Amazon.Common.DotNetCli.Tools.Options;
1110
using Amazon.Common.DotNetCli.Tools;
@@ -338,7 +337,7 @@ private async Task<Repository> SetupECRRepository(string ecrRepositoryName)
338337
}
339338

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

369+
if (response.AuthorizationData == null || response.AuthorizationData.Count == 0)
370+
{
371+
throw new ToolsException("No authorization data returned from ECR", ToolsException.CommonErrorCode.GetECRAuthTokens);
372+
}
373+
370374
var authTokenBytes = Convert.FromBase64String(response.AuthorizationData[0].AuthorizationToken);
371375
var authToken = Encoding.UTF8.GetString(authTokenBytes);
372376
var decodedTokens = authToken.Split(':');
@@ -387,7 +391,7 @@ private async Task InitiateDockerLogin(DockerCLIWrapper dockerCLI)
387391
}
388392
}
389393

390-
protected override void SaveConfigFile(JsonData data)
394+
protected override void SaveConfigFile(Dictionary<string, object> data)
391395
{
392396
this.PushDockerImageProperties.PersistSettings(this, data);
393397
}
@@ -490,7 +494,7 @@ public void ParseCommandArguments(CommandOptions values)
490494
}
491495

492496

493-
public void PersistSettings(BaseCommand<TDefaultConfig> command, JsonData data)
497+
public void PersistSettings(BaseCommand<TDefaultConfig> command, Dictionary<string, object> data)
494498
{
495499
data.SetIfNotNull(CommonDefinedCommandOptions.ARGUMENT_CONFIGURATION.ConfigFileKey, command.GetStringValueOrDefault(this.Configuration, CommonDefinedCommandOptions.ARGUMENT_CONFIGURATION, false));
496500
data.SetIfNotNull(CommonDefinedCommandOptions.ARGUMENT_FRAMEWORK.ConfigFileKey, command.GetStringValueOrDefault(this.TargetFramework, CommonDefinedCommandOptions.ARGUMENT_FRAMEWORK, false));

0 commit comments

Comments
 (0)