Skip to content

Commit

Permalink
Restore AWS_SECRET_KEY to be checked first, rename variable names.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Haberman committed Sep 20, 2013
1 parent 4d4c0a4 commit e74b809
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@
/**
* {@link AWSCredentialsProvider} implementation that provides credentials
* by looking at the: <code>AWS_ACCESS_KEY_ID</code> (or <code>AWS_ACCESS_KEY</code>) and
* <code>AWS_SECRET_ACCESS_KEY</code> (or <code>AWS_SECRET_KEY</code>) environment variables.
* <code>AWS_SECRET_KEY</code> (or <code>AWS_SECRET_ACCESS_KEY</code>) environment variables.
*/
public class EnvironmentVariableCredentialsProvider implements AWSCredentialsProvider {

/** Environment variable name for the AWS access key ID */
private static final String ACCESS_KEY_ENV_VAR = "AWS_ACCESS_KEY_ID";

/** Alternate environment variable name for the AWS access key ID */
private static final String ACCESS_KEY_ENV_VAR_2 = "AWS_ACCESS_KEY";
private static final String ALTERNATE_ACCESS_KEY_ENV_VAR = "AWS_ACCESS_KEY";

/** Environment variable name for the AWS secret key */
private static final String SECRET_KEY_ENV_VAR = "AWS_SECRET_ACCESS_KEY";
private static final String SECRET_KEY_ENV_VAR = "AWS_SECRET_KEY";

/** Alternate environment variable name for the AWS secret key */
private static final String SECRET_KEY_ENV_VAR_2 = "AWS_SECRET_KEY";
private static final String ALTERNATE_SECRET_KEY_ENV_VAR = "AWS_SECRET_ACCESS_KEY";

public AWSCredentials getCredentials() {
String accessKey = System.getenv(ACCESS_KEY_ENV_VAR);
if (accessKey == null) {
accessKey = System.getenv(ACCESS_KEY_ENV_VAR_2);
accessKey = System.getenv(ALTERNATE_ACCESS_KEY_ENV_VAR);
}

String secretKey = System.getenv(SECRET_KEY_ENV_VAR);
if (secretKey == null) {
secretKey = System.getenv(SECRET_KEY_ENV_VAR_2);
secretKey = System.getenv(ALTERNATE_SECRET_KEY_ENV_VAR);
}

if (accessKey != null && secretKey != null) {
Expand All @@ -52,8 +52,8 @@ public AWSCredentials getCredentials() {

throw new AmazonClientException(
"Unable to load AWS credentials from environment variables " +
"(" + ACCESS_KEY_ENV_VAR + " (or " + ACCESS_KEY_ENV_VAR_2 + ") and " +
SECRET_KEY_ENV_VAR + " (or " + SECRET_KEY_ENV_VAR_2 + "))");
"(" + ACCESS_KEY_ENV_VAR + " (or " + ALTERNATE_ACCESS_KEY_ENV_VAR + ") and " +
SECRET_KEY_ENV_VAR + " (or " + ALTERNATE_SECRET_KEY_ENV_VAR + "))");
}

public void refresh() {}
Expand Down

0 comments on commit e74b809

Please sign in to comment.