-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport customisable AWS SDK clients to v9 (#3184)
* Add ability to customise AWS SDK Clients for publishing from client code * Add AWS SDK client customisation for SQS subscribers * Add tests for customising AWS client config (cherry picked from commit 4e55cea) * Update documentation comments (cherry picked from commit 4f4d719) * Move AWS Client construction to a common factory class * Move missing client construction to factory class (cherry picked from commit 9d89bb4) * Resolve build issues after merge conflicts
- Loading branch information
Showing
11 changed files
with
255 additions
and
33 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/Paramore.Brighter.MessagingGateway.AWSSQS/AWSClientFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using Amazon; | ||
using Amazon.Runtime; | ||
using Amazon.SecurityToken; | ||
using Amazon.SimpleNotificationService; | ||
using Amazon.SQS; | ||
|
||
namespace Paramore.Brighter.MessagingGateway.AWSSQS | ||
{ | ||
internal class AWSClientFactory | ||
{ | ||
private AWSCredentials _credentials; | ||
private RegionEndpoint _region; | ||
private Action<ClientConfig> _clientConfigAction; | ||
|
||
public AWSClientFactory(AWSMessagingGatewayConnection connection) | ||
{ | ||
_credentials = connection.Credentials; | ||
_region = connection.Region; | ||
_clientConfigAction = connection.ClientConfigAction; | ||
} | ||
|
||
public AWSClientFactory(AWSCredentials credentials, RegionEndpoint region, Action<ClientConfig> clientConfigAction) | ||
{ | ||
_credentials = credentials; | ||
_region = region; | ||
_clientConfigAction = clientConfigAction; | ||
} | ||
|
||
public AmazonSimpleNotificationServiceClient CreateSnsClient() | ||
{ | ||
var config = new AmazonSimpleNotificationServiceConfig | ||
{ | ||
RegionEndpoint = _region | ||
}; | ||
|
||
if (_clientConfigAction != null) | ||
{ | ||
_clientConfigAction(config); | ||
} | ||
|
||
return new AmazonSimpleNotificationServiceClient(_credentials, config); | ||
} | ||
|
||
public AmazonSQSClient CreateSqsClient() | ||
{ | ||
var config = new AmazonSQSConfig | ||
{ | ||
RegionEndpoint = _region | ||
}; | ||
|
||
if (_clientConfigAction != null) | ||
{ | ||
_clientConfigAction(config); | ||
} | ||
|
||
return new AmazonSQSClient(_credentials, config); | ||
} | ||
|
||
public AmazonSecurityTokenServiceClient CreateStsClient() | ||
{ | ||
var config = new AmazonSecurityTokenServiceConfig | ||
{ | ||
RegionEndpoint = _region | ||
}; | ||
|
||
if (_clientConfigAction != null) | ||
{ | ||
_clientConfigAction(config); | ||
} | ||
|
||
return new AmazonSecurityTokenServiceClient(_credentials, config); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
tests/Paramore.Brighter.AWS.Tests/Helpers/InterceptingDelegatingHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Paramore.Brighter.AWS.Tests.Helpers | ||
{ | ||
internal class InterceptingDelegatingHandler : DelegatingHandler | ||
{ | ||
public int RequestCount { get; private set; } | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
RequestCount++; | ||
|
||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/Paramore.Brighter.AWS.Tests/Helpers/InterceptingHttpClientFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Net.Http; | ||
using Amazon.Runtime; | ||
|
||
namespace Paramore.Brighter.AWS.Tests.Helpers | ||
{ | ||
internal class InterceptingHttpClientFactory : HttpClientFactory | ||
{ | ||
private readonly InterceptingDelegatingHandler _handler; | ||
|
||
public InterceptingHttpClientFactory(InterceptingDelegatingHandler handler) | ||
{ | ||
_handler = handler; | ||
} | ||
|
||
public override HttpClient CreateHttpClient(IClientConfig clientConfig) | ||
{ | ||
return new HttpClient(_handler); | ||
} | ||
} | ||
} |
Oops, something went wrong.