Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
add EnvironmentVariableCredentialsProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
nazoking committed Nov 27, 2014
1 parent 727c0df commit 8f97bcc
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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$

Expand Down

0 comments on commit 8f97bcc

Please sign in to comment.