Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…tics.HealthChecks into ivanau-master
  • Loading branch information
unaizorrilla committed Apr 17, 2020
2 parents 06b09c2 + 9a61497 commit 345c724
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/HealthChecks.Aws.S3/S3HealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ public S3HealthCheck(S3BucketOptions bucketOptions)
{
throw new ArgumentNullException(nameof(bucketOptions));
}
if (string.IsNullOrEmpty(bucketOptions.AccessKey))
{
throw new ArgumentNullException(nameof(S3BucketOptions.AccessKey));
}
if (string.IsNullOrEmpty(bucketOptions.SecretKey))
{
throw new ArgumentNullException(nameof(S3BucketOptions.SecretKey));
}
if (bucketOptions.S3Config == null)
{
throw new ArgumentNullException(nameof(S3BucketOptions.S3Config));
Expand All @@ -34,8 +26,14 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context
{
try
{
var credentials = new BasicAWSCredentials(_bucketOptions.AccessKey, _bucketOptions.SecretKey);
using (var client = new AmazonS3Client(credentials, _bucketOptions.S3Config))
bool keysProvided = !string.IsNullOrEmpty(_bucketOptions.AccessKey) &&
!string.IsNullOrEmpty(_bucketOptions.SecretKey);

AmazonS3Client client = keysProvided
? new AmazonS3Client(_bucketOptions.AccessKey, _bucketOptions.SecretKey, _bucketOptions.S3Config)
: new AmazonS3Client(_bucketOptions.S3Config);

using (client)
{
var response = await client.ListObjectsAsync(_bucketOptions.BucketName, cancellationToken);

Expand Down

0 comments on commit 345c724

Please sign in to comment.