From 3a9c546ebbee5fd323d760065b47ab63a9ef529d Mon Sep 17 00:00:00 2001 From: John Bogovic Date: Wed, 5 Jun 2024 10:43:37 -0400 Subject: [PATCH] feat: AmazonS3Utils add ClientConfiguration --- .../saalfeldlab/n5/s3/AmazonS3Utils.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/janelia/saalfeldlab/n5/s3/AmazonS3Utils.java b/src/main/java/org/janelia/saalfeldlab/n5/s3/AmazonS3Utils.java index 603b54c..20b75ae 100644 --- a/src/main/java/org/janelia/saalfeldlab/n5/s3/AmazonS3Utils.java +++ b/src/main/java/org/janelia/saalfeldlab/n5/s3/AmazonS3Utils.java @@ -9,6 +9,7 @@ import org.janelia.saalfeldlab.n5.N5Exception; +import com.amazonaws.ClientConfiguration; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.AWSStaticCredentialsProvider; @@ -117,7 +118,14 @@ public static AmazonS3 createS3(final String uri) { return createS3(uri, (String)null, null, null); } - public static AmazonS3 createS3(final String uri, @Nullable final String s3Endpoint, @Nullable final AWSCredentialsProvider s3Credentials, @Nullable String region) { + public static AmazonS3 createS3(final String uri, @Nullable final String s3Endpoint, @Nullable final AWSCredentialsProvider s3Credentials, + @Nullable String region) { + + return createS3(uri, s3Endpoint, s3Credentials, null, region); + } + + public static AmazonS3 createS3(final String uri, @Nullable final String s3Endpoint, @Nullable final AWSCredentialsProvider s3Credentials, + @Nullable ClientConfiguration clientConfiguration, @Nullable String region) { try { final AmazonS3URI s3Uri = new AmazonS3URI(uri); @@ -134,13 +142,20 @@ public static AmazonS3 createS3(final String uri, @Nullable final String s3Endpo } } - public static AmazonS3 createS3(final AmazonS3URI s3Uri, @Nullable final String s3Endpoint, @Nullable final AWSCredentialsProvider s3Credentials, @Nullable final String region) { + public static AmazonS3 createS3(final AmazonS3URI s3Uri, @Nullable final String s3Endpoint, @Nullable final AWSCredentialsProvider s3Credentials, + @Nullable final String region) { + + return createS3(s3Uri, s3Endpoint, s3Credentials, null, region); + } + + public static AmazonS3 createS3(final AmazonS3URI s3Uri, @Nullable final String s3Endpoint, @Nullable final AWSCredentialsProvider s3Credentials, + @Nullable ClientConfiguration clientConfiguration, @Nullable final String region) { AwsClientBuilder.EndpointConfiguration endpointConfiguration = null; if (!S3_SCHEME.matcher(s3Uri.getURI().getScheme()).matches()) { endpointConfiguration = createEndpointConfiguration(s3Uri, s3Endpoint); } - return createS3(s3Uri.getBucket(), s3Credentials, endpointConfiguration, getS3Region(s3Uri, region)); + return createS3(s3Uri.getBucket(), s3Credentials, endpointConfiguration, clientConfiguration, getS3Region(s3Uri, region)); } public static AwsClientBuilder.EndpointConfiguration createEndpointConfiguration(final AmazonS3URI s3Uri, @Nullable final String s3Endpoint) { @@ -164,6 +179,16 @@ public static AmazonS3 createS3( @Nullable final AwsClientBuilder.EndpointConfiguration endpointConfiguration, @Nullable final Regions region) { + return createS3(bucketName, credentialsProvider, endpointConfiguration, null, region); + } + + public static AmazonS3 createS3( + final String bucketName, + @Nullable final AWSCredentialsProvider credentialsProvider, + @Nullable final AwsClientBuilder.EndpointConfiguration endpointConfiguration, + @Nullable final ClientConfiguration clientConfiguration, + @Nullable final Regions region) { + final boolean isAmazon = endpointConfiguration == null || AmazonS3Utils.AWS_ENDPOINT_PATTERN.matcher(endpointConfiguration.getServiceEndpoint()).find(); final AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard(); @@ -175,6 +200,9 @@ public static AmazonS3 createS3( else builder.withCredentials(credentialsProvider); + if (clientConfiguration != null) + builder.withClientConfiguration(clientConfiguration); + if (endpointConfiguration != null) builder.withEndpointConfiguration(endpointConfiguration); else if (region != null)