Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 to use default credentials when no keys #433

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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