mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 01:23:47 -05:00
Merge pull request #92 from overleaf/sk-configure-aws-region
Allow configuration of AWS region
This commit is contained in:
commit
8c0048b302
4 changed files with 34 additions and 10 deletions
|
@ -19,7 +19,8 @@
|
||||||
"type": "s3",
|
"type": "s3",
|
||||||
"awsAccessKey": "asdf",
|
"awsAccessKey": "asdf",
|
||||||
"awsSecret": "asdf",
|
"awsSecret": "asdf",
|
||||||
"s3BucketName": "com.overleaf.testbucket"
|
"s3BucketName": "com.overleaf.testbucket",
|
||||||
|
"awsRegion": "us-east-1"
|
||||||
},
|
},
|
||||||
"swapJob": {
|
"swapJob": {
|
||||||
"minProjects": 50,
|
"minProjects": 50,
|
||||||
|
|
|
@ -21,16 +21,29 @@ public class S3SwapStore implements SwapStore {
|
||||||
this(
|
this(
|
||||||
cfg.getAwsAccessKey(),
|
cfg.getAwsAccessKey(),
|
||||||
cfg.getAwsSecret(),
|
cfg.getAwsSecret(),
|
||||||
cfg.getS3BucketName()
|
cfg.getS3BucketName(),
|
||||||
|
cfg.getAwsRegion()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
S3SwapStore(
|
S3SwapStore(
|
||||||
String accessKey,
|
String accessKey,
|
||||||
String secret,
|
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;
|
this.bucketName = bucketName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ public class SwapStoreConfig {
|
||||||
"noop",
|
"noop",
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
null,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -16,19 +17,22 @@ public class SwapStoreConfig {
|
||||||
private String awsAccessKey;
|
private String awsAccessKey;
|
||||||
private String awsSecret;
|
private String awsSecret;
|
||||||
private String s3BucketName;
|
private String s3BucketName;
|
||||||
|
private String awsRegion;
|
||||||
|
|
||||||
public SwapStoreConfig() {}
|
public SwapStoreConfig() {}
|
||||||
|
|
||||||
public SwapStoreConfig(
|
public SwapStoreConfig(
|
||||||
String awsAccessKey,
|
String awsAccessKey,
|
||||||
String awsSecret,
|
String awsSecret,
|
||||||
String s3BucketName
|
String s3BucketName,
|
||||||
|
String awsRegion
|
||||||
) {
|
) {
|
||||||
this(
|
this(
|
||||||
"s3",
|
"s3",
|
||||||
awsAccessKey,
|
awsAccessKey,
|
||||||
awsSecret,
|
awsSecret,
|
||||||
s3BucketName
|
s3BucketName,
|
||||||
|
awsRegion
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,12 +40,14 @@ public class SwapStoreConfig {
|
||||||
String type,
|
String type,
|
||||||
String awsAccessKey,
|
String awsAccessKey,
|
||||||
String awsSecret,
|
String awsSecret,
|
||||||
String s3BucketName
|
String s3BucketName,
|
||||||
|
String awsRegion
|
||||||
) {
|
) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.awsAccessKey = awsAccessKey;
|
this.awsAccessKey = awsAccessKey;
|
||||||
this.awsSecret = awsSecret;
|
this.awsSecret = awsSecret;
|
||||||
this.s3BucketName = s3BucketName;
|
this.s3BucketName = s3BucketName;
|
||||||
|
this.awsRegion = awsRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
|
@ -60,12 +66,15 @@ public class SwapStoreConfig {
|
||||||
return s3BucketName;
|
return s3BucketName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAwsRegion() { return awsRegion; }
|
||||||
|
|
||||||
public SwapStoreConfig sanitisedCopy() {
|
public SwapStoreConfig sanitisedCopy() {
|
||||||
return new SwapStoreConfig(
|
return new SwapStoreConfig(
|
||||||
type,
|
type,
|
||||||
awsAccessKey == null ? null : "<awsAccessKey>",
|
awsAccessKey == null ? null : "<awsAccessKey>",
|
||||||
awsSecret == null ? null : "<awsSecret>",
|
awsSecret == null ? null : "<awsSecret>",
|
||||||
s3BucketName
|
s3BucketName,
|
||||||
|
awsRegion
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ public class S3SwapStoreTest {
|
||||||
private static final String accessKey = null;
|
private static final String accessKey = null;
|
||||||
private static final String secret = null;
|
private static final String secret = null;
|
||||||
private static final String bucketName = "com.overleaf.testbucket";
|
private static final String bucketName = "com.overleaf.testbucket";
|
||||||
|
private static final String region = "us-east-1";
|
||||||
|
|
||||||
private S3SwapStore s3;
|
private S3SwapStore s3;
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ public class S3SwapStoreTest {
|
||||||
s3 = null;
|
s3 = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s3 = new S3SwapStore(accessKey, secret, bucketName);
|
s3 = new S3SwapStore(accessKey, secret, bucketName, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Ignore
|
// @Ignore
|
||||||
|
|
Loading…
Reference in a new issue