-
Notifications
You must be signed in to change notification settings - Fork 332
Refactor: Use per-request STS credentials #1629
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ | |
| import java.util.function.Supplier; | ||
| import org.slf4j.LoggerFactory; | ||
| import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
| import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
| import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; | ||
| import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
| import software.amazon.awssdk.services.sts.StsClient; | ||
| import software.amazon.awssdk.services.sts.StsClientBuilder; | ||
|
|
@@ -61,21 +63,31 @@ public interface StorageConfiguration { | |
| Optional<Duration> gcpAccessTokenLifespan(); | ||
|
|
||
| default Supplier<StsClient> stsClientSupplier() { | ||
| return stsClientSupplier(true); | ||
| } | ||
|
|
||
| default Supplier<StsClient> stsClientSupplier(boolean withCredentials) { | ||
| return Suppliers.memoize( | ||
| () -> { | ||
| StsClientBuilder stsClientBuilder = StsClient.builder(); | ||
| if (awsAccessKey().isPresent() && awsSecretKey().isPresent()) { | ||
| LoggerFactory.getLogger(StorageConfiguration.class) | ||
| .warn("Using hard-coded AWS credentials - this is not recommended for production"); | ||
| StaticCredentialsProvider awsCredentialsProvider = | ||
| StaticCredentialsProvider.create( | ||
| AwsBasicCredentials.create(awsAccessKey().get(), awsSecretKey().get())); | ||
| stsClientBuilder.credentialsProvider(awsCredentialsProvider); | ||
| if (withCredentials) { | ||
| stsClientBuilder.credentialsProvider(stsCredentials()); | ||
| } | ||
| return stsClientBuilder.build(); | ||
| }); | ||
| } | ||
|
|
||
| default AwsCredentialsProvider stsCredentials() { | ||
| if (awsAccessKey().isPresent() && awsSecretKey().isPresent()) { | ||
| LoggerFactory.getLogger(StorageConfiguration.class) | ||
| .warn("Using hard-coded AWS credentials - this is not recommended for production"); | ||
| return StaticCredentialsProvider.create( | ||
| AwsBasicCredentials.create(awsAccessKey().get(), awsSecretKey().get())); | ||
| } else { | ||
| return DefaultCredentialsProvider.create(); | ||
|
||
| } | ||
| } | ||
|
|
||
| default Supplier<GoogleCredentials> gcpCredentialsSupplier() { | ||
| return Suppliers.memoize( | ||
| () -> { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason to keep Logger getter in this method rather outside ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, it was just a copy-paste.... will fix.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, refactoring this in current PR is awkward - I would not like to add a logger field to this interface. Adding a class looks like an overkill.
Would you mind if I moved this to a production readiness check in a follow-up PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds fair !