Allow configuration of AWS region

This commit is contained in:
Shane Kilkelly
2021-01-22 09:53:12 +00:00
parent 6d44851869
commit c520ecd70d
4 changed files with 34 additions and 10 deletions

View File

@@ -21,16 +21,29 @@ public class S3SwapStore implements SwapStore {
this(
cfg.getAwsAccessKey(),
cfg.getAwsSecret(),
cfg.getS3BucketName()
cfg.getS3BucketName(),
cfg.getAwsRegion()
);
}
S3SwapStore(
String accessKey,
String secret,
String bucketName
String bucketName,
String region
) {
s3 = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secret))).build();
String regionToUse = null;
if (region == null) {
regionToUse = "us-east-1";
} else {
regionToUse = region;
}
s3 = AmazonS3ClientBuilder
.standard()
.withRegion(regionToUse)
.withCredentials(
new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secret))
).build();
this.bucketName = bucketName;
}

View File

@@ -9,6 +9,7 @@ public class SwapStoreConfig {
"noop",
null,
null,
null,
null
);
@@ -16,19 +17,22 @@ public class SwapStoreConfig {
private String awsAccessKey;
private String awsSecret;
private String s3BucketName;
private String awsRegion;
public SwapStoreConfig() {}
public SwapStoreConfig(
String awsAccessKey,
String awsSecret,
String s3BucketName
String s3BucketName,
String awsRegion
) {
this(
"s3",
awsAccessKey,
awsSecret,
s3BucketName
s3BucketName,
awsRegion
);
}
@@ -36,12 +40,14 @@ public class SwapStoreConfig {
String type,
String awsAccessKey,
String awsSecret,
String s3BucketName
String s3BucketName,
String awsRegion
) {
this.type = type;
this.awsAccessKey = awsAccessKey;
this.awsSecret = awsSecret;
this.s3BucketName = s3BucketName;
this.awsRegion = awsRegion;
}
public String getType() {
@@ -60,12 +66,15 @@ public class SwapStoreConfig {
return s3BucketName;
}
public String getAwsRegion() { return awsRegion; }
public SwapStoreConfig sanitisedCopy() {
return new SwapStoreConfig(
type,
awsAccessKey == null ? null : "<awsAccessKey>",
awsSecret == null ? null : "<awsSecret>",
s3BucketName
s3BucketName,
awsRegion
);
}