From c0048e30def3f336cea62a0bfac8ddc3741d2c9e Mon Sep 17 00:00:00 2001 From: Pavel Shahoiko Date: Tue, 18 Jul 2023 16:59:39 +0300 Subject: [PATCH] Added the ability to inject a custom AmazonS3 client --- .../conductor/s3/config/S3Configuration.java | 16 ++++++++++++++-- .../conductor/s3/storage/S3PayloadStorage.java | 5 ++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/awss3-storage/src/main/java/com/netflix/conductor/s3/config/S3Configuration.java b/awss3-storage/src/main/java/com/netflix/conductor/s3/config/S3Configuration.java index a188c85046..f4930e9c0b 100644 --- a/awss3-storage/src/main/java/com/netflix/conductor/s3/config/S3Configuration.java +++ b/awss3-storage/src/main/java/com/netflix/conductor/s3/config/S3Configuration.java @@ -21,6 +21,9 @@ import com.netflix.conductor.core.utils.IDGenerator; import com.netflix.conductor.s3.storage.S3PayloadStorage; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; + @Configuration @EnableConfigurationProperties(S3Properties.class) @ConditionalOnProperty(name = "conductor.external-payload-storage.type", havingValue = "s3") @@ -28,7 +31,16 @@ public class S3Configuration { @Bean public ExternalPayloadStorage s3ExternalPayloadStorage( - IDGenerator idGenerator, S3Properties properties) { - return new S3PayloadStorage(idGenerator, properties); + IDGenerator idGenerator, S3Properties properties, AmazonS3 s3Client) { + return new S3PayloadStorage(idGenerator, properties, s3Client); + } + + @ConditionalOnProperty( + name = "conductor.external-payload-storage.s3.use_default_client", + havingValue = "true", + matchIfMissing = true) + @Bean + public AmazonS3 amazonS3() { + return AmazonS3ClientBuilder.standard().withRegion(region).build(); } } diff --git a/awss3-storage/src/main/java/com/netflix/conductor/s3/storage/S3PayloadStorage.java b/awss3-storage/src/main/java/com/netflix/conductor/s3/storage/S3PayloadStorage.java index 8ac530ea54..32bbf55a0c 100644 --- a/awss3-storage/src/main/java/com/netflix/conductor/s3/storage/S3PayloadStorage.java +++ b/awss3-storage/src/main/java/com/netflix/conductor/s3/storage/S3PayloadStorage.java @@ -30,7 +30,6 @@ import com.amazonaws.HttpMethod; import com.amazonaws.SdkClientException; import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.model.*; /** @@ -52,12 +51,12 @@ public class S3PayloadStorage implements ExternalPayloadStorage { private final String bucketName; private final long expirationSec; - public S3PayloadStorage(IDGenerator idGenerator, S3Properties properties) { + public S3PayloadStorage(IDGenerator idGenerator, S3Properties properties, AmazonS3 s3Client) { this.idGenerator = idGenerator; + this.s3Client = s3Client; bucketName = properties.getBucketName(); expirationSec = properties.getSignedUrlExpirationDuration().getSeconds(); String region = properties.getRegion(); - s3Client = AmazonS3ClientBuilder.standard().withRegion(region).build(); } /**