S3: Add support for custom apiserver By setting the `hostname` value for a s3 backend, you can configure lfs to use a custom s3-compatible apiserver. Change-Id: I8f98b8171234959df008e871c91e44fdd039431c
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/s3/S3LargeFileRepository.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/s3/S3LargeFileRepository.java index a10242a..e10450c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/lfs/s3/S3LargeFileRepository.java +++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/s3/S3LargeFileRepository.java
@@ -15,6 +15,7 @@ package com.googlesource.gerrit.plugins.lfs.s3; import com.google.common.base.MoreObjects; +import com.google.common.base.Strings; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.googlesource.gerrit.plugins.lfs.LfsBackend; @@ -35,6 +36,7 @@ private static S3Config getS3Config(LfsGlobalConfig config, LfsBackend backendConfig) { String section = backendConfig.type.name(); + String hostname = config.getString(section, backendConfig.name, "hostname"); String region = config.getString(section, backendConfig.name, "region"); String bucket = config.getString(section, backendConfig.name, "bucket"); String storageClass = @@ -47,6 +49,12 @@ String accessKey = config.getString(section, backendConfig.name, "accessKey"); String secretKey = config.getString(section, backendConfig.name, "secretKey"); + if (!Strings.isNullOrEmpty(hostname)) { + return new S3Config( + hostname, region, bucket, storageClass, accessKey, secretKey, expirationSeconds, + disableSslVerify); + } + return new S3Config( region, bucket, storageClass, accessKey, secretKey, expirationSeconds, disableSslVerify); }
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md index 3013f5c..383cb9b 100644 --- a/src/main/resources/Documentation/config.md +++ b/src/main/resources/Documentation/config.md
@@ -154,6 +154,11 @@ The following configuration options are only used when the backend is `s3`. +s3.hostname +: Custom hostname for the S3 API server. This will allow for easier local testing +of gerrit instances with lfs storage and for the utilization of custom storage +solutions. If not specified, lfs will use AWS as the backend. + s3.region : [Amazon region](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) the S3 storage bucket is residing in.