Skip to content

Commit

Permalink
s3: add urihandler support
Browse files Browse the repository at this point in the history
  • Loading branch information
RussTorres committed Feb 26, 2024
1 parent 04b6d41 commit 9a68c8a
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,32 @@ public static S3Handler getSharedInstance()
private static synchronized void buildInstance() throws IOException {
if (SHARED_INSTANCE == null) {
try {
final AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
final AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).build();
SHARED_INSTANCE = new S3Handler(s3Client);
final AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard();

if (this.s3Parameters.containsKey("aws_secret_access_key") && this.s3Parameters.containsKey("aws_access_key_id")){
final AWSCredentials credentials = new BasicAWSCredentials(this.s3Parameters.get("aws_access_key_id"), this.s3Parameters.get("aws_secret_access_key"));
final AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
clientBuilder.setCredentials(credentialsProvider);
} else if (this.s3Parameters.containsKey("profile_name")) {
final AWSCredentialsProvider credentialsProvider = new ProfileCredentialsProvider(this.s3Parameters.get("profile_name"));
clientBuilder.setCredentials(credentialsProvider);
} else {
final AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
clientBuilder.setCredentials(credentialsProvider);
}

String region = (String) this.s3Parameters.getOrDefault("region_name", clientBuilder.getRegion());
if (this.s3Parameters.containsKey("endpoint_url")) {
final EndpointConfiguration endpointConfig = new EndpointConfiguration(this.s3Parameters.get("endpoint_url"), region);
final AmazonS3 s3Client = clientBuilder.withEndpointConfiguration(endpointConfig).build();
SHARED_INSTANCE = new S3Handler(s3Client);
} else {
final AmazonS3 s3Client = clientBuilder.withRegion(region).build();
SHARED_INSTANCE = new S3Handler(s3Client);
}
//final AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
//final AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).build();
//SHARED_INSTANCE = new S3Handler(s3Client);
} catch (final AmazonServiceException ase) {
throw new IOException("Amazon S3 service failure for error type " + ase.getErrorType(), ase);
} catch (final AmazonClientException ace) {
Expand Down

0 comments on commit 9a68c8a

Please sign in to comment.