Merge pull request #30458 from overleaf/mj-git-bridge-local-swap
[git-bridge] Mock S3 locally with minio GitOrigin-RevId: d56659d601e4450f69332202b86e61a443375101
This commit is contained in:
committed by
Copybot
parent
32845170ff
commit
bf662f74f5
+20
-6
@@ -2,6 +2,7 @@ package uk.ac.ic.wlgitbridge.bridge.swap.store;
|
||||
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
|
||||
import com.amazonaws.services.s3.AmazonS3;
|
||||
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
||||
import com.amazonaws.services.s3.model.*;
|
||||
@@ -17,22 +18,35 @@ public class S3SwapStore implements SwapStore {
|
||||
private final String bucketName;
|
||||
|
||||
public S3SwapStore(SwapStoreConfig cfg) {
|
||||
this(cfg.getAwsAccessKey(), cfg.getAwsSecret(), cfg.getS3BucketName(), cfg.getAwsRegion());
|
||||
this(
|
||||
cfg.getAwsAccessKey(),
|
||||
cfg.getAwsSecret(),
|
||||
cfg.getS3BucketName(),
|
||||
cfg.getAwsRegion(),
|
||||
cfg.getAwsEndpoint());
|
||||
}
|
||||
|
||||
S3SwapStore(String accessKey, String secret, String bucketName, String region) {
|
||||
S3SwapStore(String accessKey, String secret, String bucketName, String region, String endpoint) {
|
||||
String regionToUse = null;
|
||||
if (region == null) {
|
||||
regionToUse = "us-east-1";
|
||||
} else {
|
||||
regionToUse = region;
|
||||
}
|
||||
s3 =
|
||||
|
||||
AmazonS3ClientBuilder builder =
|
||||
AmazonS3ClientBuilder.standard()
|
||||
.withRegion(regionToUse)
|
||||
.withCredentials(
|
||||
new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secret)))
|
||||
.build();
|
||||
new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secret)));
|
||||
|
||||
if (endpoint != null && !endpoint.isEmpty()) {
|
||||
builder
|
||||
.enablePathStyleAccess()
|
||||
.withEndpointConfiguration(new EndpointConfiguration(endpoint, regionToUse));
|
||||
} else {
|
||||
builder.withRegion(regionToUse);
|
||||
}
|
||||
s3 = builder.build();
|
||||
this.bucketName = bucketName;
|
||||
}
|
||||
|
||||
|
||||
+22
-5
@@ -5,28 +5,40 @@ package uk.ac.ic.wlgitbridge.bridge.swap.store;
|
||||
*/
|
||||
public class SwapStoreConfig {
|
||||
|
||||
public static final SwapStoreConfig NOOP = new SwapStoreConfig("noop", null, null, null, null);
|
||||
public static final SwapStoreConfig NOOP =
|
||||
new SwapStoreConfig("noop", null, null, null, null, null);
|
||||
|
||||
private String type;
|
||||
private String awsAccessKey;
|
||||
private String awsSecret;
|
||||
private String s3BucketName;
|
||||
private String awsRegion;
|
||||
private String awsEndpoint;
|
||||
|
||||
public SwapStoreConfig() {}
|
||||
|
||||
public SwapStoreConfig(
|
||||
String awsAccessKey, String awsSecret, String s3BucketName, String awsRegion) {
|
||||
this("s3", awsAccessKey, awsSecret, s3BucketName, awsRegion);
|
||||
String awsAccessKey,
|
||||
String awsSecret,
|
||||
String s3BucketName,
|
||||
String awsRegion,
|
||||
String awsEndpoint) {
|
||||
this("s3", awsAccessKey, awsSecret, s3BucketName, awsRegion, awsEndpoint);
|
||||
}
|
||||
|
||||
SwapStoreConfig(
|
||||
String type, String awsAccessKey, String awsSecret, String s3BucketName, String awsRegion) {
|
||||
String type,
|
||||
String awsAccessKey,
|
||||
String awsSecret,
|
||||
String s3BucketName,
|
||||
String awsRegion,
|
||||
String awsEndpoint) {
|
||||
this.type = type;
|
||||
this.awsAccessKey = awsAccessKey;
|
||||
this.awsSecret = awsSecret;
|
||||
this.s3BucketName = s3BucketName;
|
||||
this.awsRegion = awsRegion;
|
||||
this.awsEndpoint = awsEndpoint;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
@@ -49,13 +61,18 @@ public class SwapStoreConfig {
|
||||
return awsRegion;
|
||||
}
|
||||
|
||||
public String getAwsEndpoint() {
|
||||
return awsEndpoint;
|
||||
}
|
||||
|
||||
public SwapStoreConfig sanitisedCopy() {
|
||||
return new SwapStoreConfig(
|
||||
type,
|
||||
awsAccessKey == null ? null : "<awsAccessKey>",
|
||||
awsSecret == null ? null : "<awsSecret>",
|
||||
s3BucketName,
|
||||
awsRegion);
|
||||
awsRegion,
|
||||
awsEndpoint);
|
||||
}
|
||||
|
||||
public static SwapStoreConfig sanitisedCopy(SwapStoreConfig swapStore) {
|
||||
|
||||
Reference in New Issue
Block a user