Skip to content

Commit 0ba68d5

Browse files
authored
chore: Update User-Agent string (#311)
1 parent 51130b6 commit 0ba68d5

File tree

12 files changed

+68
-53
lines changed

12 files changed

+68
-53
lines changed

src/Amazon.Common.DotNetCli.Tools/Amazon.Common.DotNetCli.Tools.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<FileVersion>3.1.0.1</FileVersion>
77
</PropertyGroup>
88
<ItemGroup>
9-
<PackageReference Include="AWSSDK.Core" Version="3.7.202.21" />
10-
<PackageReference Include="AWSSDK.ECR" Version="3.7.201.16" />
11-
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.200.52" />
12-
<PackageReference Include="AWSSDK.S3" Version="3.7.205.7" />
13-
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.202.3" />
14-
<PackageReference Include="AWSSDK.SSO" Version="3.7.201.3" />
15-
<PackageReference Include="AWSSDK.SSOOIDC" Version="3.7.201.9" />
9+
<PackageReference Include="AWSSDK.Core" Version="3.7.303.20" />
10+
<PackageReference Include="AWSSDK.ECR" Version="3.7.301.75" />
11+
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.301.6" />
12+
<PackageReference Include="AWSSDK.S3" Version="3.7.307.21" />
13+
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.300.81" />
14+
<PackageReference Include="AWSSDK.SSO" Version="3.7.300.80" />
15+
<PackageReference Include="AWSSDK.SSOOIDC" Version="3.7.301.75" />
1616
</ItemGroup>
1717
<PropertyGroup>
1818
<NoWarn>1701;1702;1705;1591</NoWarn>

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ protected abstract string ToolName
8282
get;
8383
}
8484

85+
protected string UserAgentString => GetUserAgentString();
86+
8587
/// <summary>
8688
/// The common options used by every command
8789
/// </summary>
@@ -753,11 +755,10 @@ private int WaitForIndexResponse(int min, int max)
753755
public IToolLogger Logger { get; protected set; }
754756
public string WorkingDirectory { get; set; }
755757

756-
protected void SetUserAgentString()
758+
protected string GetUserAgentString()
757759
{
758760
string version = this.GetType().GetTypeInfo().Assembly.GetName().Version.ToString();
759-
Util.Internal.InternalSDKUtils.SetUserAgent(this.ToolName,
760-
version);
761+
return $"lib/{this.ToolName}#{version}";
761762
}
762763

763764
IAmazonSecurityTokenService _stsClient;
@@ -767,12 +768,11 @@ public IAmazonSecurityTokenService STSClient
767768
{
768769
if (this._stsClient == null)
769770
{
770-
SetUserAgentString();
771-
772771
var config = new AmazonSecurityTokenServiceConfig();
773772
config.RegionEndpoint = DetermineAWSRegion();
774773

775774
this._stsClient = new AmazonSecurityTokenServiceClient(DetermineAWSCredentials(), config);
775+
Utilities.SetUserAgentString((AmazonServiceClient)_stsClient, UserAgentString);
776776
}
777777
return this._stsClient;
778778
}
@@ -786,12 +786,11 @@ public IAmazonIdentityManagementService IAMClient
786786
{
787787
if (this._iamClient == null)
788788
{
789-
SetUserAgentString();
790-
791789
var config = new AmazonIdentityManagementServiceConfig();
792790
config.RegionEndpoint = DetermineAWSRegion();
793791

794792
this._iamClient = new AmazonIdentityManagementServiceClient(DetermineAWSCredentials(), config);
793+
Utilities.SetUserAgentString((AmazonServiceClient)_iamClient, UserAgentString);
795794
}
796795
return this._iamClient;
797796
}
@@ -805,13 +804,12 @@ public IAmazonS3 S3Client
805804
{
806805
if (this._s3Client == null)
807806
{
808-
SetUserAgentString();
809-
810807
var config = new AmazonS3Config();
811808
config.RegionEndpoint = DetermineAWSRegion();
812809
config.Timeout = TimeSpan.FromHours(1);
813810

814811
this._s3Client = new AmazonS3Client(DetermineAWSCredentials(), config);
812+
Utilities.SetUserAgentString((AmazonServiceClient)_s3Client, UserAgentString);
815813
}
816814
return this._s3Client;
817815
}
@@ -825,12 +823,11 @@ public IAmazonECR ECRClient
825823
{
826824
if (this._ecrClient == null)
827825
{
828-
SetUserAgentString();
829-
830826
var config = new AmazonECRConfig();
831827
config.RegionEndpoint = DetermineAWSRegion();
832828

833829
this._ecrClient = new AmazonECRClient(DetermineAWSCredentials(), config);
830+
Utilities.SetUserAgentString((AmazonServiceClient)_ecrClient, UserAgentString);
834831
}
835832
return this._ecrClient;
836833
}

src/Amazon.Common.DotNetCli.Tools/Utilities.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ public static class Utilities
2828
/// </summary>
2929
private readonly static Regex EnvironmentVariableTokens = new Regex(@"[$][(].*?[)]", RegexOptions.Compiled);
3030

31+
/// <summary>
32+
/// Adds a delegate to the AWS service client to update the User-Agent string before every request.
33+
/// </summary>
34+
/// <param name="amazonServiceClient">The AWS service client.</param>
35+
/// <param name="userAgent">The User-Agent string that will be set.</param>
36+
public static void SetUserAgentString(AmazonServiceClient amazonServiceClient, string userAgent)
37+
{
38+
const string userAgentHeader = "User-Agent";
39+
40+
var beforeRequestEvent = new RequestEventHandler((sender, e) =>
41+
{
42+
if (!(e is WebServiceRequestEventArgs args) || !args.Headers.TryGetValue(userAgentHeader, out var header) || header.Contains(userAgent))
43+
return;
44+
45+
args.Headers[userAgentHeader] += " " + userAgent;
46+
});
47+
48+
amazonServiceClient.BeforeRequestEvent += beforeRequestEvent;
49+
}
50+
3151
/// <summary>
3252
/// Replaces $(Variable) tokens with environment variables
3353
/// </summary>

src/Amazon.ECS.Tools/Amazon.ECS.Tools.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackAsTool>true</PackAsTool>
1111
<ToolCommandName>dotnet-ecs</ToolCommandName>
1212
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
13-
<Version>3.5.5</Version>
13+
<Version>3.5.6</Version>
1414
<AssemblyName>dotnet-ecs</AssemblyName>
1515
<Company>Amazon.com, Inc</Company>
1616
<Authors>Amazon Web Services</Authors>
@@ -20,13 +20,13 @@
2020
</PropertyGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="AWSSDK.CloudWatchEvents" Version="3.7.202.8" />
24-
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.201.9" />
25-
<PackageReference Include="AWSSDK.Core" Version="3.7.202.21" />
26-
<PackageReference Include="AWSSDK.EC2" Version="3.7.218.3" />
27-
<PackageReference Include="AWSSDK.ECS" Version="3.7.201.22" />
28-
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.200.52" />
29-
<PackageReference Include="AWSSDK.S3" Version="3.7.205.7" />
23+
<PackageReference Include="AWSSDK.CloudWatchEvents" Version="3.7.300.80" />
24+
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.305.21" />
25+
<PackageReference Include="AWSSDK.Core" Version="3.7.303.20" />
26+
<PackageReference Include="AWSSDK.EC2" Version="3.7.324" />
27+
<PackageReference Include="AWSSDK.ECS" Version="3.7.305.42" />
28+
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.301.6" />
29+
<PackageReference Include="AWSSDK.S3" Version="3.7.307.21" />
3030
</ItemGroup>
3131

3232
<ItemGroup>

src/Amazon.ECS.Tools/Commands/ECSBaseCommand.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ public IAmazonCloudWatchEvents CWEClient
5151
{
5252
if (this._cweClient == null)
5353
{
54-
SetUserAgentString();
55-
5654
var config = new AmazonCloudWatchEventsConfig();
5755
config.RegionEndpoint = DetermineAWSRegion();
5856

5957
this._cweClient = new AmazonCloudWatchEventsClient(DetermineAWSCredentials(), config);
58+
Utilities.SetUserAgentString((AmazonServiceClient)_cweClient, UserAgentString);
6059
}
6160
return this._cweClient;
6261
}
@@ -70,12 +69,11 @@ public IAmazonCloudWatchLogs CWLClient
7069
{
7170
if (this._cwlClient == null)
7271
{
73-
SetUserAgentString();
74-
7572
var config = new AmazonCloudWatchLogsConfig();
7673
config.RegionEndpoint = DetermineAWSRegion();
7774

7875
this._cwlClient = new AmazonCloudWatchLogsClient(DetermineAWSCredentials(), config);
76+
Utilities.SetUserAgentString((AmazonServiceClient)_cwlClient, UserAgentString);
7977
}
8078
return this._cwlClient;
8179
}
@@ -89,12 +87,11 @@ public IAmazonECS ECSClient
8987
{
9088
if (this._ecsClient == null)
9189
{
92-
SetUserAgentString();
93-
9490
var config = new AmazonECSConfig();
9591
config.RegionEndpoint = DetermineAWSRegion();
9692

9793
this._ecsClient = new AmazonECSClient(DetermineAWSCredentials(), config);
94+
Utilities.SetUserAgentString((AmazonServiceClient)_ecsClient, UserAgentString);
9895
}
9996
return this._ecsClient;
10097
}
@@ -108,12 +105,11 @@ public IAmazonEC2 EC2Client
108105
{
109106
if (this._ec2Client == null)
110107
{
111-
SetUserAgentString();
112-
113108
var config = new AmazonEC2Config();
114109
config.RegionEndpoint = DetermineAWSRegion();
115110

116111
this._ec2Client = new AmazonEC2Client(DetermineAWSCredentials(), config);
112+
Utilities.SetUserAgentString((AmazonServiceClient)_ec2Client, UserAgentString);
117113
}
118114
return this._ec2Client;
119115
}

src/Amazon.ElasticBeanstalk.Tools/Amazon.ElasticBeanstalk.Tools.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackAsTool>true</PackAsTool>
1111
<ToolCommandName>dotnet-eb</ToolCommandName>
1212
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
13-
<Version>4.3.3</Version>
13+
<Version>4.3.4</Version>
1414
<AssemblyName>dotnet-eb</AssemblyName>
1515
<Authors>Amazon Web Services</Authors>
1616
<Copyright>Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.</Copyright>
@@ -25,9 +25,9 @@
2525
</ItemGroup>
2626

2727
<ItemGroup>
28-
<PackageReference Include="AWSSDK.ElasticBeanstalk" Version="3.7.200.52" />
29-
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.200.52" />
30-
<PackageReference Include="AWSSDK.S3" Version="3.7.205.7" />
28+
<PackageReference Include="AWSSDK.ElasticBeanstalk" Version="3.7.300.80" />
29+
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.301.6" />
30+
<PackageReference Include="AWSSDK.S3" Version="3.7.307.21" />
3131
</ItemGroup>
3232

3333
<PropertyGroup>

src/Amazon.ElasticBeanstalk.Tools/Commands/EBBaseCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Amazon.Common.DotNetCli.Tools;
88
using Amazon.Common.DotNetCli.Tools.Options;
99
using System.Threading.Tasks;
10+
using Amazon.Runtime;
1011

1112
namespace Amazon.ElasticBeanstalk.Tools.Commands
1213
{
@@ -22,7 +23,7 @@ public EBBaseCommand(IToolLogger logger, string workingDirectory, IList<CommandO
2223
{
2324
}
2425

25-
protected override string ToolName => "AWSElasticBeanstalkToolsDotnet";
26+
protected override string ToolName => EBConstants.TOOLNAME;
2627

2728
IAmazonElasticBeanstalk _ebClient;
2829
public IAmazonElasticBeanstalk EBClient
@@ -31,12 +32,11 @@ public IAmazonElasticBeanstalk EBClient
3132
{
3233
if (this._ebClient == null)
3334
{
34-
SetUserAgentString();
35-
3635
var config = new AmazonElasticBeanstalkConfig();
3736
config.RegionEndpoint = DetermineAWSRegion();
3837

3938
this._ebClient = new AmazonElasticBeanstalkClient(DetermineAWSCredentials(), config);
39+
Utilities.SetUserAgentString((AmazonServiceClient)_ebClient, UserAgentString);
4040
}
4141
return this._ebClient;
4242
}

src/Amazon.ElasticBeanstalk.Tools/EBConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace Amazon.ElasticBeanstalk.Tools
66
{
77
public static class EBConstants
88
{
9+
public const string TOOLNAME = "AWSElasticBeanstalkToolsDotnet";
10+
911
public const string DEFAULT_MANIFEST = @"
1012
{
1113
""manifestVersion"": 1,

src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<Copyright>Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.</Copyright>
1616
<Product>AWS Lambda Tools for .NET CLI</Product>
1717
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
18-
<Version>5.10.4</Version>
18+
<Version>5.10.5</Version>
1919
</PropertyGroup>
2020
<ItemGroup>
2121
<Content Include="Resources\build-lambda-zip.exe">
@@ -36,10 +36,10 @@
3636
</ItemGroup>
3737
<ItemGroup>
3838
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
39-
<PackageReference Include="AWSSDK.CloudFormation" Version="3.7.203.46" />
40-
<PackageReference Include="AWSSDK.Lambda" Version="3.7.201.48" />
41-
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.200.52" />
42-
<PackageReference Include="AWSSDK.S3" Version="3.7.205.7" />
39+
<PackageReference Include="AWSSDK.CloudFormation" Version="3.7.307.6" />
40+
<PackageReference Include="AWSSDK.Lambda" Version="3.7.305.12" />
41+
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.301.6" />
42+
<PackageReference Include="AWSSDK.S3" Version="3.7.307.21" />
4343
<PackageReference Include="YamlDotNet.Signed" Version="5.2.1" />
4444
</ItemGroup>
4545
<PropertyGroup>

src/Amazon.Lambda.Tools/Commands/LambdaBaseCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Amazon.Common.DotNetCli.Tools;
66
using Amazon.Common.DotNetCli.Tools.Commands;
77
using Amazon.Common.DotNetCli.Tools.Options;
8+
using Amazon.Runtime;
89

910
namespace Amazon.Lambda.Tools.Commands
1011
{
@@ -32,10 +33,10 @@ public IAmazonLambda LambdaClient
3233
{
3334
if (this._lambdaClient != null) return this._lambdaClient;
3435

35-
SetUserAgentString();
3636
var config = new AmazonLambdaConfig {RegionEndpoint = DetermineAWSRegion()};
3737

3838
this._lambdaClient = new AmazonLambdaClient(DetermineAWSCredentials(), config);
39+
Utilities.SetUserAgentString((AmazonServiceClient)_lambdaClient, UserAgentString);
3940
return this._lambdaClient;
4041
}
4142
set { this._lambdaClient = value; }
@@ -48,13 +49,12 @@ public IAmazonCloudFormation CloudFormationClient
4849
{
4950
if (this._cloudFormationClient == null)
5051
{
51-
SetUserAgentString();
52-
5352
AmazonCloudFormationConfig config =
5453
new AmazonCloudFormationConfig {RegionEndpoint = DetermineAWSRegion()};
5554

5655

5756
this._cloudFormationClient = new AmazonCloudFormationClient(DetermineAWSCredentials(), config);
57+
Utilities.SetUserAgentString((AmazonServiceClient)_cloudFormationClient, UserAgentString);
5858
}
5959
return this._cloudFormationClient;
6060
}

0 commit comments

Comments
 (0)