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

Adding a defaultCredentialsProvider for AWS S3 #56

Merged
merged 4 commits into from
Jul 11, 2024
Merged

Conversation

sachinkarve
Copy link
Contributor

@sachinkarve sachinkarve commented Jul 11, 2024

Since setting up an EC2 instance and loading it with CP4M image would be time consuming, I have manually tested the flow.

Test Cases:

  1. Existing flow with aws credentials in local config file
    Result: Works as before

  2. 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

  3. 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

@@ -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;
Copy link
Contributor

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

Copy link
Contributor Author

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());
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this to constructor

@@ -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) {
Copy link
Contributor

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

Copy link
Contributor Author

@sachinkarve sachinkarve Jul 11, 2024

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.

@sachinkarve sachinkarve merged commit 6d25555 into main Jul 11, 2024
3 checks passed
@sachinkarve sachinkarve deleted the sach/feat-s3-creds branch July 11, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants