Skip to content

Commit 02340bd

Browse files
committed
feat(s3): Refactor S3FileSystemFactory to use constants for AWS region management
1 parent 4f63ee9 commit 02340bd

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/main/java/dev/themeinerlp/bluemap/s3/storage/S3FileSystemFactory.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import java.util.Objects;
99

1010
final class S3FileSystemFactory {
11+
12+
private static final String AWS_REGION_KEY = "aws.region";
13+
public static final String DEFAULT_AWS_REGION = "us-east-1";
14+
1115
public record S3Fs(FileSystem fileSystem, URI uri) {}
1216

1317
private static S3FileSystemProvider PROVIDER;
@@ -23,21 +27,19 @@ public static S3Fs build(S3Configuration cfg) {
2327
final boolean thirdParty = cfg.getEndpointUrl() != null && !cfg.getEndpointUrl().isBlank();
2428
try {
2529
final URI uri;
26-
if (!thirdParty) {
27-
// AWS S3 – the provider uses the default region/credentials chain
28-
PROVIDER = new S3FileSystemProvider();
29-
System.setProperty("aws.region", cfg.getRegion() != null ? cfg.getRegion() : "us-east-1");
30-
uri = URI.create("s3://" + cfg.getBucketName());
31-
} else {
30+
if (thirdParty) {
3231
PROVIDER = new S3XFileSystemProvider();
3332
var url = URI.create(cfg.getEndpointUrl());
3433
System.setProperty("s3.spi.endpoint-protocol", url.toString().startsWith("https") ? "https" : "http");
35-
System.setProperty("aws.region", cfg.getRegion() != null ? cfg.getRegion() : "us-east-1");
34+
System.setProperty(AWS_REGION_KEY, cfg.getRegion() != null ? cfg.getRegion() : DEFAULT_AWS_REGION);
3635
String userInfo = buildUserInfo(cfg);
3736
uri = new URI("s3x", userInfo, url.getHost(), url.getPort(), "/" + cfg.getBucketName(), null, null);
37+
} else {
38+
// AWS S3 – the provider uses the default region/credentials chain
39+
PROVIDER = new S3FileSystemProvider();
40+
System.setProperty(AWS_REGION_KEY, cfg.getRegion() != null ? cfg.getRegion() : DEFAULT_AWS_REGION);
41+
uri = URI.create("s3://" + cfg.getBucketName());
3842
}
39-
System.out.println("Using S3 FileSystem Provider: " + PROVIDER.getClass().getName());
40-
System.out.println("Using S3 URI: " + uri);
4143
FileSystem fs = PROVIDER.getFileSystem(uri);
4244
return new S3Fs(fs, uri);
4345
} catch (Exception e) {

0 commit comments

Comments
 (0)