Skip to content

Commit 914fc5a

Browse files
committed
Allow for custom S3 endpoints
1 parent a669d75 commit 914fc5a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

DynmapCore/src/main/java/org/dynmap/storage/aws_s3/AWSS3MapStorage.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.dynmap.storage.aws_s3;
22

33
import java.io.IOException;
4+
import java.net.URI;
45
import java.nio.charset.StandardCharsets;
56
import java.security.MessageDigest;
67
import java.security.NoSuchAlgorithmException;
@@ -221,7 +222,7 @@ public String toString() {
221222
}
222223

223224
private String bucketname;
224-
private String region;
225+
private Region region;
225226
private String access_key_id;
226227
private String secret_access_key;
227228
private String prefix;
@@ -248,10 +249,20 @@ public boolean init(DynmapCore core) {
248249
}
249250
// Get our settings
250251
bucketname = core.configuration.getString("storage/bucketname", "dynmap");
251-
region = core.configuration.getString("storage/region", "us-east-1");
252252
access_key_id = core.configuration.getString("storage/aws_access_key_id", System.getenv("AWS_ACCESS_KEY_ID"));
253253
secret_access_key = core.configuration.getString("storage/aws_secret_access_key", System.getenv("AWS_SECRET_ACCESS_KEY"));
254254
prefix = core.configuration.getString("storage/prefix", "");
255+
256+
// Either use a custom region, or one of the default AWS regions
257+
String region_name = core.configuration.getString("storage/region", "us-east-1");
258+
String region_endpoint = core.configuration.getString("storage/override_endpoint", "");
259+
260+
if (region_endpoint.length() > 0) {
261+
region = Region.of(region_name, URI.create(region_endpoint));
262+
} else {
263+
region = Region.fromString(region_name);
264+
}
265+
255266
if ((prefix.length() > 0) && (prefix.charAt(prefix.length()-1) != '/')) {
256267
prefix += '/';
257268
}
@@ -763,7 +774,7 @@ private S3Client getConnection() throws S3Exception, StorageShutdownException {
763774
if (cpoolCount < POOLSIZE) { // Still more we can have
764775
c = new DefaultS3ClientBuilder()
765776
.credentialsProvider(() -> AwsBasicCredentials.create(access_key_id, secret_access_key))
766-
.region(Region.fromString(region))
777+
.region(region)
767778
.httpClient(URLConnectionSdkHttpClient.create())
768779
.build();
769780
if (c == null) {

0 commit comments

Comments
 (0)