Add protocol configuration to Amazon S3 transport
Before this change, attempting to use the jgit Amazon S3 transport with an S3-compatible service that requires https (for example, Backblaze B2) results in an error: $ jgit push b2 fatal: amazon-s3://metadaddy-jgit/repos/test/objects: error in packed-refs This change adds a "protocol" property to the Amazon S3 transport configuration, defaulting to http, and uses that value when constructing the URL for the S3 service. Example configuration for Backblaze B2: accesskey: <Your B2 Application Key> secretkey: <Your B2 Application Key Id> acl: private protocol: https domain: s3.us-west-004.backblazeb2.com region: us-west-004 aws.api.signature.version: 4 Behavior after this change: $ jgit push b2 Counting objects: 3 Finding sources: 100% (3/3) Getting sizes: 100% (2/2) Compressing objects: 100% (37/37) Writing objects: 100% (3/3) Put pack-673f9bb.idx: 100% (1/1) To amazon-s3://.jgit_b2@metadaddy-jgit/repos/test * [new branch] main -> main Change-Id: I03bdbb3510fb81a416c225a720178f42eec41b21
This commit is contained in:
parent
0e9708803f
commit
e06ce59607
|
@ -171,6 +171,9 @@ private static MessageDigest newMD5() {
|
|||
/** S3 Bucket Domain. */
|
||||
private final String domain;
|
||||
|
||||
/** S3 Protocol, "https" or "http"; defaults to "http". */
|
||||
private final String protocol;
|
||||
|
||||
/** S3 Region. */
|
||||
private final String region;
|
||||
|
||||
|
@ -183,6 +186,7 @@ interface Keys {
|
|||
String CRYPTO_ALG = "crypto.algorithm"; //$NON-NLS-1$
|
||||
String CRYPTO_VER = "crypto.version"; //$NON-NLS-1$
|
||||
String ACL = "acl"; //$NON-NLS-1$
|
||||
String PROTOCOL = "protocol"; //$NON-NLS-1$
|
||||
String DOMAIN = "domain"; //$NON-NLS-1$
|
||||
String REGION = "region"; //$NON-NLS-1$
|
||||
String HTTP_RETRY = "httpclient.retry-max"; //$NON-NLS-1$
|
||||
|
@ -246,6 +250,8 @@ public AmazonS3(final Properties props) {
|
|||
awsApiSignatureVersion));
|
||||
}
|
||||
|
||||
protocol = props.getProperty(Keys.PROTOCOL, "http"); //$NON-NLS-1$
|
||||
|
||||
domain = props.getProperty(Keys.DOMAIN, "s3.amazonaws.com"); //$NON-NLS-1$
|
||||
|
||||
publicKey = props.getProperty(Keys.ACCESS_KEY);
|
||||
|
@ -590,7 +596,8 @@ HttpURLConnection open(final String method, final String bucket,
|
|||
final String key, final Map<String, String> args)
|
||||
throws IOException {
|
||||
final StringBuilder urlstr = new StringBuilder();
|
||||
urlstr.append("http://"); //$NON-NLS-1$
|
||||
urlstr.append(protocol); //$NON-NLS-1$
|
||||
urlstr.append("://"); //$NON-NLS-1$
|
||||
urlstr.append(bucket);
|
||||
urlstr.append('.');
|
||||
urlstr.append(domain);
|
||||
|
|
Loading…
Reference in New Issue