Browse Source

Allow for using custom s3 host with lfs server

By default, it will generate hostname using the aws region passed to the
constructor.

This will allow for easier testing, since you can just spin up a local
minio (or other s3-compatible storage service) instance and point the
application at that for the storage mechanism.

It will also allow for storing lfs objects on-prem.

Change-Id: I2566b1fcce58f3d306ddd23a8da702ef5a451c7b
Signed-off-by: Pat Long <pllong@arista.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
master
Pat Long 5 years ago committed by Matthias Sohn
parent
commit
d27dceb384
  1. 1
      org.eclipse.jgit.lfs.server/resources/org/eclipse/jgit/lfs/server/internal/LfsServerText.properties
  2. 1
      org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/internal/LfsServerText.java
  3. 49
      org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/S3Config.java
  4. 6
      org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/S3Repository.java

1
org.eclipse.jgit.lfs.server/resources/org/eclipse/jgit/lfs/server/internal/LfsServerText.properties

@ -4,6 +4,7 @@ objectNotFound=Object ''{0}'' not found
undefinedS3AccessKey=S3 configuration: 'accessKey' is undefined undefinedS3AccessKey=S3 configuration: 'accessKey' is undefined
undefinedS3Bucket=S3 configuration: 'bucket' is undefined undefinedS3Bucket=S3 configuration: 'bucket' is undefined
undefinedS3Region=S3 configuration: 'region' is undefined undefinedS3Region=S3 configuration: 'region' is undefined
undefinedS3Hostname=S3 configuration: 'hostname' is undefined
undefinedS3SecretKey=S3 configuration: 'secretKey' is undefined undefinedS3SecretKey=S3 configuration: 'secretKey' is undefined
undefinedS3StorageClass=S3 configuration: 'storageClass' is undefined undefinedS3StorageClass=S3 configuration: 'storageClass' is undefined
unparsableEndpoint=Unable to parse service endpoint: {0} unparsableEndpoint=Unable to parse service endpoint: {0}

1
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/internal/LfsServerText.java

@ -33,6 +33,7 @@ public class LfsServerText extends TranslationBundle {
/***/ public String undefinedS3AccessKey; /***/ public String undefinedS3AccessKey;
/***/ public String undefinedS3Bucket; /***/ public String undefinedS3Bucket;
/***/ public String undefinedS3Region; /***/ public String undefinedS3Region;
/***/ public String undefinedS3Hostname;
/***/ public String undefinedS3SecretKey; /***/ public String undefinedS3SecretKey;
/***/ public String undefinedS3StorageClass; /***/ public String undefinedS3StorageClass;
/***/ public String unparsableEndpoint; /***/ public String unparsableEndpoint;

49
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/S3Config.java

@ -16,6 +16,7 @@ package org.eclipse.jgit.lfs.server.s3;
* @since 4.3 * @since 4.3
*/ */
public class S3Config { public class S3Config {
private final String hostname;
private final String region; private final String region;
private final String bucket; private final String bucket;
private final String storageClass; private final String storageClass;
@ -25,8 +26,12 @@ public class S3Config {
private final boolean disableSslVerify; private final boolean disableSslVerify;
/** /**
* <p>Constructor for S3Config.</p> * <p>
* Constructor for S3Config.
* </p>
* *
* @param hostname
* S3 API host
* @param region * @param region
* AWS region * AWS region
* @param bucket * @param bucket
@ -43,10 +48,12 @@ public class S3Config {
* @param disableSslVerify * @param disableSslVerify
* if {@code true} disable Amazon server certificate and hostname * if {@code true} disable Amazon server certificate and hostname
* verification * verification
* @since 5.8
*/ */
public S3Config(String region, String bucket, String storageClass, public S3Config(String hostname, String region, String bucket, String storageClass,
String accessKey, String secretKey, int expirationSeconds, String accessKey, String secretKey, int expirationSeconds,
boolean disableSslVerify) { boolean disableSslVerify) {
this.hostname = hostname;
this.region = region; this.region = region;
this.bucket = bucket; this.bucket = bucket;
this.storageClass = storageClass; this.storageClass = storageClass;
@ -56,6 +63,44 @@ public class S3Config {
this.disableSslVerify = disableSslVerify; this.disableSslVerify = disableSslVerify;
} }
/**
* <p>Constructor for S3Config.</p>
*
* @param region
* AWS region
* @param bucket
* S3 storage bucket
* @param storageClass
* S3 storage class
* @param accessKey
* access key for authenticating to AWS
* @param secretKey
* secret key for authenticating to AWS
* @param expirationSeconds
* period in seconds after which requests signed for this bucket
* will expire
* @param disableSslVerify
* if {@code true} disable Amazon server certificate and hostname
* verification
*/
public S3Config(String region, String bucket, String storageClass,
String accessKey, String secretKey, int expirationSeconds,
boolean disableSslVerify) {
this(String.format("s3-%s.amazonaws.com", region), region, bucket, //$NON-NLS-1$
storageClass, accessKey, secretKey, expirationSeconds,
disableSslVerify);
}
/**
* Get the <code>hostname</code>.
*
* @return Get the S3 API host
* @since 5.8
*/
public String getHostname() {
return hostname;
}
/** /**
* Get the <code>region</code>. * Get the <code>region</code>.
* *

6
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/S3Repository.java

@ -159,6 +159,8 @@ public class S3Repository implements LargeFileRepository {
config.getBucket()); config.getBucket());
assertNotEmpty(LfsServerText.get().undefinedS3Region, assertNotEmpty(LfsServerText.get().undefinedS3Region,
config.getRegion()); config.getRegion());
assertNotEmpty(LfsServerText.get().undefinedS3Hostname,
config.getHostname());
assertNotEmpty(LfsServerText.get().undefinedS3SecretKey, assertNotEmpty(LfsServerText.get().undefinedS3SecretKey,
config.getSecretKey()); config.getSecretKey());
assertNotEmpty(LfsServerText.get().undefinedS3StorageClass, assertNotEmpty(LfsServerText.get().undefinedS3StorageClass,
@ -173,8 +175,8 @@ public class S3Repository implements LargeFileRepository {
private URL getObjectUrl(AnyLongObjectId oid) { private URL getObjectUrl(AnyLongObjectId oid) {
try { try {
return new URL(String.format("https://s3-%s.amazonaws.com/%s/%s", //$NON-NLS-1$ return new URL(String.format("https://%s/%s/%s", //$NON-NLS-1$
s3Config.getRegion(), s3Config.getBucket(), s3Config.getHostname(), s3Config.getBucket(),
getPath(oid))); getPath(oid)));
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
throw new IllegalArgumentException(MessageFormat.format( throw new IllegalArgumentException(MessageFormat.format(

Loading…
Cancel
Save