From 58b2c36cd38b459fe2b4ebe99f46cb4b5c1997f1 Mon Sep 17 00:00:00 2001 From: kovstas Date: Mon, 23 Sep 2024 18:56:11 +0200 Subject: [PATCH] Add S3_FORCE_GLOBAL_BUCKET_ACCESS environment variable to allow users to modify the forceGlobalBucketAccessEnabled S3 client setting --- src/main/scala/fm/sbt/S3URLHandler.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/scala/fm/sbt/S3URLHandler.scala b/src/main/scala/fm/sbt/S3URLHandler.scala index df02610..7a67ee7 100644 --- a/src/main/scala/fm/sbt/S3URLHandler.scala +++ b/src/main/scala/fm/sbt/S3URLHandler.scala @@ -297,12 +297,15 @@ final class S3URLHandler extends URLHandler { } yield new EndpointConfiguration(serviceEndpoint, signingRegion) // Path Style Access is deprecated by Amazon S3 but LocalStack seems to want to use it - val pathStyleAccess: Boolean = Option(System.getenv("S3_PATH_STYLE_ACCESS")).map{ _.toBoolean }.getOrElse(false) + val pathStyleAccess: Boolean = Option(System.getenv("S3_PATH_STYLE_ACCESS")).exists(_.toBoolean) + + // Rerouting can cause replacing the user custom endpoint with the S3 default one (s3.amazonaws.com). Default is true + val forceGlobalBucketAccessEnabled: Boolean = Option(System.getenv("S3_FORCE_GLOBAL_BUCKET_ACCESS")).forall(_.toBoolean) val tmp: AmazonS3ClientBuilder = AmazonS3Client.builder() .withCredentials(getCredentialsProvider(bucket)) .withClientConfiguration(getProxyConfiguration) - .withForceGlobalBucketAccessEnabled(true) + .withForceGlobalBucketAccessEnabled(forceGlobalBucketAccessEnabled) .withPathStyleAccessEnabled(pathStyleAccess) // Only one of the endpointConfiguration or region can be set at a time.