From e06ce59607d1e8da0d83ae2e36777a6caef0a2e5 Mon Sep 17 00:00:00 2001 From: Pat Patterson Date: Thu, 6 Apr 2023 08:05:56 -0700 Subject: [PATCH] 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: secretkey: 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 --- .../src/org/eclipse/jgit/transport/AmazonS3.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index 4fec5da78..d48252174 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -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 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);