From 8f97bcc55951a7632dce44a4a09b14bfeec5e79d Mon Sep 17 00:00:00 2001 From: nazoking Date: Thu, 27 Nov 2014 15:57:03 +0900 Subject: [PATCH] add EnvironmentVariableCredentialsProvider --- .../jgit/transport/TransportAmazonS3.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java index 72fec619b53..fa4f6d00b80 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java @@ -189,6 +189,9 @@ private Properties loadProperties() throws NotSupportedException { throw new RuntimeException(e); } } + if ("ENV".equals(uri.getUser())) { //$NON-NLS-1$ + return environmentVariableProfile(); + } File propsFile; if (local != null) { if (local.getDirectory() != null) { @@ -219,6 +222,31 @@ private Properties loadProperties() throws NotSupportedException { return props; } + // see + // https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-core/src/main/java/com/amazonaws/auth/EnvironmentVariableCredentialsProvider.java + private Properties environmentVariableProfile() { + Properties props = new Properties(); + String accesskey = System.getenv("AWS_ACCESS_KEY_ID"); //$NON-NLS-1$ + if(accesskey==null){ + accesskey = System.getenv("AWS_ACCESS_KEY"); //$NON-NLS-1$ + } + String secretkey = System.getenv("AWS_SECRET_KEY"); //$NON-NLS-1$ + if (secretkey == null) { + secretkey = System.getenv("AWS_SECRET_ACCESS_KEY"); //$NON-NLS-1$ + } + if (accesskey != null) { + props.setProperty("accesskey", accesskey); //$NON-NLS-1$ + } + if (secretkey != null) { + props.setProperty("secretkey", secretkey); //$NON-NLS-1$ + } + String token = System.getenv("AWS_SESSION_TOKEN"); //$NON-NLS-1$ + if (token != null) { + props.setProperty("token", token); //$NON-NLS-1$ + } + return props; + } + private static final Pattern jsonStringPropertyPattern = Pattern .compile("\"([^\"]*)\"\\s*:\\s*\"([^\"]*)\""); //$NON-NLS-1$