Skip to content

Commit

Permalink
Fix #1418 Expose AwsCredentialsProvider to AmazonS3InstallationService
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Jan 14, 2025
1 parent 441b008 commit 40feb5c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ public class AmazonS3InstallationService implements InstallationService {
private boolean historicalDataEnabled;

public AmazonS3InstallationService(String bucketName) {
this(bucketName, null);
}

public AmazonS3InstallationService(String bucketName, AwsCredentialsProvider credentialsProvider) {
this.bucketName = bucketName;
this.credentialsProvider = credentialsProvider;
}

@Override
public Initializer initializer() {
return (app) -> {
// The first access to S3 tends to be slow on AWS Lambda.
this.credentialsProvider = DefaultCredentialsProvider.create();
AwsCredentials credentials = createCredentials(credentialsProvider);
AwsCredentials credentials = createCredentials(getAwsCredentialsProvider());
if (credentials == null || credentials.accessKeyId() == null) {
throw new IllegalStateException("AWS credentials not found");
}
Expand Down Expand Up @@ -299,6 +303,13 @@ private Installer toInstaller(ResponseBytes<GetObjectResponse> s3Object) throws
return JsonOps.fromJson(json, DefaultInstaller.class);
}

protected AwsCredentialsProvider getAwsCredentialsProvider() {
if (this.credentialsProvider == null) {
this.credentialsProvider = DefaultCredentialsProvider.create();
}
return this.credentialsProvider;
}

protected AwsCredentials createCredentials(AwsCredentialsProvider provider) {
return provider.resolveCredentials();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ public class AmazonS3OAuthStateService implements OAuthStateService {
private AwsCredentialsProvider credentialsProvider;

public AmazonS3OAuthStateService(String bucketName) {
this(bucketName, null);
}

public AmazonS3OAuthStateService(String bucketName, AwsCredentialsProvider credentialsProvider) {
this.bucketName = bucketName;
this.credentialsProvider = credentialsProvider;
}

@Override
public Initializer initializer() {
return (app) -> {
// The first access to S3 tends to be slow on AWS Lambda.
this.credentialsProvider = DefaultCredentialsProvider.create();
AwsCredentials credentials = createCredentials(credentialsProvider);
AwsCredentials credentials = createCredentials(getAwsCredentialsProvider());
if (credentials == null || credentials.accessKeyId() == null) {
throw new IllegalStateException("AWS credentials not found");
}
Expand Down Expand Up @@ -98,6 +102,13 @@ public void deleteStateFromDatastore(String state) throws Exception {
}
}

protected AwsCredentialsProvider getAwsCredentialsProvider() {
if (this.credentialsProvider == null) {
this.credentialsProvider = DefaultCredentialsProvider.create();
}
return this.credentialsProvider;
}

protected AwsCredentials createCredentials(AwsCredentialsProvider provider) {
return provider.resolveCredentials();
}
Expand Down

0 comments on commit 40feb5c

Please sign in to comment.