-
Notifications
You must be signed in to change notification settings - Fork 17
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
Adding a defaultCredentialsProvider for AWS S3 #56
Conversation
@@ -29,24 +33,26 @@ public class S3PreProcessor<T extends Message> implements PreProcessor<T> { | |||
private final String region; | |||
private final String bucket; | |||
private final @Nullable String textMessageAddition; | |||
private final StaticCredentialsProvider credentialsProvider; | |||
private @Nullable StaticCredentialsProvider staticCredentialsProvider; |
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.
should be any reason to remove the final
here
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.
Moved the 2nd assignment to variable in else
condition which allows on-time assignment, in turn allowing final
@@ -75,11 +81,11 @@ public ThreadState<T> run(ThreadState<T> in) { | |||
|
|||
public void sendRequest(byte[] media, String senderID, String extension) { | |||
String key = senderID + '_' + Instant.now().toEpochMilli() + '.' + extension; | |||
|
|||
AwsCredentialsProvider credentialsProvider = Objects.requireNonNullElse(this.staticCredentialsProvider, DefaultCredentialsProvider.create()); |
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.
why not push this logic up into the constructor so that you don't have to do a null check here?
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.
Moved this to constructor
…rovider in a way the variable can be static
@@ -73,13 +83,12 @@ public ThreadState<T> run(ThreadState<T> in) { | |||
Identifier.random())); // TODO: remove last message | |||
} | |||
|
|||
public void sendRequest(byte[] media, String senderID, String extension) { | |||
public void sendRequest(byte[] media, String senderID, String extension, AwsCredentialsProvider credentials) { |
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.
you shouldn't need to pass the credentials? this should have access to this.credentials
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.
Fixed it. I was debating making it a local variable and overlooked, but this makes more sense.
Since setting up an EC2 instance and loading it with CP4M image would be time consuming, I have manually tested the flow.
Test Cases:
Existing flow with aws credentials in local config file
Result: Works as before
To simulate AWS EC2 instance-like credential behavior, the test uses a specific item in the AWS SDK credentials provider chain: the credentials file located in the local .aws folder. This file occupies the fourth position in the chain. The credentials provided by IAM roles attached to EC2 instances are positioned sixth in this chain
Result: Works by picking the credentials from credentials file
To test a fail case when using defaultCredentialsProvider, deleted the credentials from credentials file in .aws
Result: S3 Client fails with an error
Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain
as expected