From 644a0cb14e24296486c1e9963b10a7f34a55a334 Mon Sep 17 00:00:00 2001 From: jweissBHG Date: Sun, 19 Jul 2020 12:27:06 -0400 Subject: [PATCH 1/4] [jhw] allow override of aws endpoint --- src/Amazon.Core/Models/AwsClient.cs | 8 ++++---- src/Amazon.DynamoDb/DynamoDbClient.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Amazon.Core/Models/AwsClient.cs b/src/Amazon.Core/Models/AwsClient.cs index 4dabb4cb..3db30631 100755 --- a/src/Amazon.Core/Models/AwsClient.cs +++ b/src/Amazon.Core/Models/AwsClient.cs @@ -15,13 +15,13 @@ public abstract class AwsClient private readonly AwsService service; protected readonly IAwsCredential credential; - public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential) + public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, string? endpoint = null) { this.service = service ?? throw new ArgumentNullException(nameof(service)); Region = region ?? throw new ArgumentNullException(nameof(region)); this.credential = credential ?? throw new ArgumentNullException(nameof(credential)); - Endpoint = $"https://{service.Name}.{region.Name}.amazonaws.com/"; + Endpoint = endpoint ?? $"https://{service.Name}.{region.Name}.amazonaws.com/"; this.httpClient = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip @@ -33,14 +33,14 @@ public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential }; } - public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, HttpClient httpClient) + public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, HttpClient httpClient, string? endpoint = null) { this.service = service ?? throw new ArgumentNullException(nameof(service)); Region = region ?? throw new ArgumentNullException(nameof(region)); this.credential = credential ?? throw new ArgumentNullException(nameof(credential)); this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); - Endpoint = $"https://{service.Name}.{region.Name}.amazonaws.com/"; + Endpoint = endpoint ?? $"https://{service.Name}.{region.Name}.amazonaws.com/"; } public string Endpoint { get; } diff --git a/src/Amazon.DynamoDb/DynamoDbClient.cs b/src/Amazon.DynamoDb/DynamoDbClient.cs index d739a342..7fa97c37 100755 --- a/src/Amazon.DynamoDb/DynamoDbClient.cs +++ b/src/Amazon.DynamoDb/DynamoDbClient.cs @@ -17,8 +17,8 @@ public sealed class DynamoDbClient : AwsClient private readonly JsonSerializerOptions SerializerOptions; - public DynamoDbClient(AwsRegion region, IAwsCredential credential) - : base(AwsService.DynamoDb, region, credential) + public DynamoDbClient(AwsRegion region, IAwsCredential credential, string? endpoint = null) + : base(AwsService.DynamoDb, region, credential, endpoint) { httpClient.Timeout = TimeSpan.FromSeconds(10); From a2f8718bd4b4b367ff6a58cec70b8c50685c54eb Mon Sep 17 00:00:00 2001 From: jweissBHG Date: Sun, 19 Jul 2020 12:55:42 -0400 Subject: [PATCH 2/4] [jhw] keep backwards compatibility --- src/Amazon.Core/Models/AwsClient.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Amazon.Core/Models/AwsClient.cs b/src/Amazon.Core/Models/AwsClient.cs index 3db30631..ffdaee2c 100755 --- a/src/Amazon.Core/Models/AwsClient.cs +++ b/src/Amazon.Core/Models/AwsClient.cs @@ -15,6 +15,18 @@ public abstract class AwsClient private readonly AwsService service; protected readonly IAwsCredential credential; + public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential) + : this(service, region, credential, (string?)null) { } + + public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, HttpClient httpClient) + : this(service, region, credential, httpClient, null) { } + + public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, HttpClient httpClient, string? endpoint = null) + : this(service, region, credential, endpoint) + { + this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); + } + public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, string? endpoint = null) { this.service = service ?? throw new ArgumentNullException(nameof(service)); @@ -33,15 +45,7 @@ public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential }; } - public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, HttpClient httpClient, string? endpoint = null) - { - this.service = service ?? throw new ArgumentNullException(nameof(service)); - Region = region ?? throw new ArgumentNullException(nameof(region)); - this.credential = credential ?? throw new ArgumentNullException(nameof(credential)); - this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); - - Endpoint = endpoint ?? $"https://{service.Name}.{region.Name}.amazonaws.com/"; - } + public string Endpoint { get; } From 1647180943c8a8dad7036658187644c942db0429 Mon Sep 17 00:00:00 2001 From: jweissBHG Date: Sun, 19 Jul 2020 12:58:37 -0400 Subject: [PATCH 3/4] [jhw] no default nulls --- src/Amazon.Core/Models/AwsClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Amazon.Core/Models/AwsClient.cs b/src/Amazon.Core/Models/AwsClient.cs index ffdaee2c..fa510b60 100755 --- a/src/Amazon.Core/Models/AwsClient.cs +++ b/src/Amazon.Core/Models/AwsClient.cs @@ -21,13 +21,13 @@ public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, HttpClient httpClient) : this(service, region, credential, httpClient, null) { } - public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, HttpClient httpClient, string? endpoint = null) + public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, HttpClient httpClient, string? endpoint) : this(service, region, credential, endpoint) { this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); } - public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, string? endpoint = null) + public AwsClient(AwsService service, AwsRegion region, IAwsCredential credential, string? endpoint) { this.service = service ?? throw new ArgumentNullException(nameof(service)); Region = region ?? throw new ArgumentNullException(nameof(region)); From a8e34b8d6985a7a169bfc31648f00e75e87ca7ae Mon Sep 17 00:00:00 2001 From: jweissBHG Date: Mon, 20 Jul 2020 07:30:21 -0400 Subject: [PATCH 4/4] [jhw] backwards compatibility with constructor --- src/Amazon.DynamoDb/DynamoDbClient.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Amazon.DynamoDb/DynamoDbClient.cs b/src/Amazon.DynamoDb/DynamoDbClient.cs index 203f2aff..e41f9877 100755 --- a/src/Amazon.DynamoDb/DynamoDbClient.cs +++ b/src/Amazon.DynamoDb/DynamoDbClient.cs @@ -18,7 +18,10 @@ public sealed class DynamoDbClient : AwsClient } }; - public DynamoDbClient(AwsRegion region, IAwsCredential credential, string? endpoint = null) + public DynamoDbClient(AwsRegion region, IAwsCredential credential) + : this(region, credential, null) { } + + public DynamoDbClient(AwsRegion region, IAwsCredential credential, string? endpoint) : base(AwsService.DynamoDb, region, credential, endpoint) { httpClient.Timeout = TimeSpan.FromSeconds(10);