Skip to content

Commit

Permalink
AWS SDK for Java 1.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AWS committed Jun 27, 2014
1 parent a8e776f commit 35299b6
Show file tree
Hide file tree
Showing 84 changed files with 9,725 additions and 585 deletions.
2 changes: 1 addition & 1 deletion META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: AWS SDK for Java
Bundle-SymbolicName: com.amazonaws.sdk;singleton:=true
Bundle-Version: 1.8.1
Bundle-Version: 1.8.2
Bundle-Vendor: Amazon Technologies, Inc
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.apache.commons.codec;bundle-version="1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>aws-java-sdk</artifactId>
<packaging>jar</packaging>
<name>AWS SDK for Java</name>
<version>1.8.2-SNAPSHOT</version>
<version>1.8.2</version>
<description>The Amazon Web Services SDK for Java provides Java APIs for building software on AWS' cost-effective, scalable, and reliable infrastructure products. The AWS Java SDK allows developers to code against APIs for all of Amazon's infrastructure web services (Amazon S3, Amazon EC2, Amazon SQS, Amazon Relational Database Service, Amazon AutoScaling, etc).</description>
<url>https://aws.amazon.com/sdkforjava</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@
* permissions and limitations under the License.
*/
package com.amazonaws.auth;

import static com.amazonaws.SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR;
import static com.amazonaws.SDKGlobalConfiguration.ALTERNATE_ACCESS_KEY_ENV_VAR;
import static com.amazonaws.SDKGlobalConfiguration.ALTERNATE_SECRET_KEY_ENV_VAR;
import static com.amazonaws.SDKGlobalConfiguration.SECRET_KEY_ENV_VAR;
import static com.amazonaws.SDKGlobalConfiguration.AWS_SESSION_TOKEN_ENV_VAR;

import com.amazonaws.AmazonClientException;
import com.amazonaws.util.StringUtils;

/**
* {@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_KEY</code> (or <code>AWS_SECRET_ACCESS_KEY</code>) environment variables.
*/
public class EnvironmentVariableCredentialsProvider implements AWSCredentialsProvider {

@Override
public AWSCredentials getCredentials() {
String accessKey = System.getenv(ACCESS_KEY_ENV_VAR);
if (accessKey == null) {
Expand All @@ -39,13 +41,18 @@ public AWSCredentials getCredentials() {
secretKey = System.getenv(ALTERNATE_SECRET_KEY_ENV_VAR);
}

String sessionToken = System.getenv(AWS_SESSION_TOKEN_ENV_VAR);
accessKey = StringUtils.trim(accessKey);
secretKey = StringUtils.trim(secretKey);
String sessionToken =
StringUtils.trim(System.getenv(AWS_SESSION_TOKEN_ENV_VAR));

if (StringUtils.isNullOrEmpty(accessKey)
|| StringUtils.isNullOrEmpty(secretKey)) {

if (accessKey == null || secretKey == null || accessKey.length() == 0 || secretKey.length() == 0) {
throw new AmazonClientException(
"Unable to load AWS credentials from environment variables " +
"(" + ACCESS_KEY_ENV_VAR + " (or " + ALTERNATE_ACCESS_KEY_ENV_VAR + ") and " +
SECRET_KEY_ENV_VAR + " (or " + ALTERNATE_SECRET_KEY_ENV_VAR + "))");
"(" + ACCESS_KEY_ENV_VAR + " (or " + ALTERNATE_ACCESS_KEY_ENV_VAR + ") and " +
SECRET_KEY_ENV_VAR + " (or " + ALTERNATE_SECRET_KEY_ENV_VAR + "))");
}

return sessionToken == null ?
Expand All @@ -54,6 +61,7 @@ public AWSCredentials getCredentials() {
new BasicSessionCredentials(accessKey, secretKey, sessionToken);
}

@Override
public void refresh() {}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
* permissions and limitations under the License.
*/
package com.amazonaws.auth;

import static com.amazonaws.SDKGlobalConfiguration.ACCESS_KEY_SYSTEM_PROPERTY;
import static com.amazonaws.SDKGlobalConfiguration.SECRET_KEY_SYSTEM_PROPERTY;

import com.amazonaws.AmazonClientException;
import com.amazonaws.util.StringUtils;

/**
* {@link AWSCredentialsProvider} implementation that provides credentials by
Expand All @@ -25,21 +27,27 @@
*/
public class SystemPropertiesCredentialsProvider implements AWSCredentialsProvider {

@Override
public AWSCredentials getCredentials() {
String accessKey = System.getProperty(ACCESS_KEY_SYSTEM_PROPERTY);
String secretKey = System.getProperty(SECRET_KEY_SYSTEM_PROPERTY);
if (accessKey != null &&
secretKey != null && accessKey.length() > 0 && secretKey.length() > 0) {
return new BasicAWSCredentials(
accessKey,
secretKey);
String accessKey =
StringUtils.trim(System.getProperty(ACCESS_KEY_SYSTEM_PROPERTY));

String secretKey =
StringUtils.trim(System.getProperty(SECRET_KEY_SYSTEM_PROPERTY));

if (StringUtils.isNullOrEmpty(accessKey)
|| StringUtils.isNullOrEmpty(secretKey)) {

throw new AmazonClientException(
"Unable to load AWS credentials from Java system "
+ "properties (" + ACCESS_KEY_SYSTEM_PROPERTY + " and "
+ SECRET_KEY_SYSTEM_PROPERTY + ")");
}

throw new AmazonClientException(
"Unable to load AWS credentials from Java system properties " +
"(" + ACCESS_KEY_SYSTEM_PROPERTY + " and " + SECRET_KEY_SYSTEM_PROPERTY + ")");
return new BasicAWSCredentials(accessKey, secretKey);
}

@Override
public void refresh() {}

@Override
Expand Down
38 changes: 29 additions & 9 deletions src/main/java/com/amazonaws/internal/config/InternalConfig.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2010-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
*
* http://aws.amazon.com/apache2.0
*
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
Expand Down Expand Up @@ -35,7 +35,9 @@
*/
@Immutable
public class InternalConfig {

private static final Log log = LogFactory.getLog(InternalConfig.class);

static final String DEFAULT_CONFIG_RESOURCE = "awssdk_config_default.json";
static final String CONFIG_OVERRIDE_RESOURCE = "awssdk_config_override.json";
private static final String SERVICE_REGION_DELIMITOR = "/";
Expand All @@ -46,27 +48,36 @@ public class InternalConfig {
private final Map<String, SignerConfig> serviceSigners;
private final Map<String, HttpClientConfig> httpClients;

private final String userAgentTemplate;

/**
* @param defaults default configuration
* @param override override configuration
* @param override override configuration
*/
InternalConfig(InternalConfigJsonHelper defaults, InternalConfigJsonHelper override) {
SignerConfigJsonHelper scb = defaults.getDefaultSigner();
this.defaultSignerConfig = scb == null ? null : scb.build();

regionSigners = mergeSignerMap(defaults.getRegionSigners(),
override.getRegionSigners(), "region");
serviceSigners = mergeSignerMap(defaults.getServiceSigners(),
override.getServiceSigners(), "service");
serviceRegionSigners = mergeSignerMap(defaults.getServiceRegionSigners(),
override.getServiceRegionSigners(),
override.getServiceRegionSigners(),
"service" + SERVICE_REGION_DELIMITOR + "region");
httpClients = merge(defaults.getHttpClients(), override.getHttpClients());

if (override.getUserAgentTemplate() != null) {
userAgentTemplate = override.getUserAgentTemplate();
} else {
userAgentTemplate = defaults.getUserAgentTemplate();
}
}

/**
* Returns an immutable map by merging the override signer configuration
* into the default signer configuration for the given theme.
*
*
* @param defaults
* default signer configuration
* @param override
Expand Down Expand Up @@ -107,7 +118,7 @@ private <C extends Builder<T>, T> Map<String, T> buildMap(JsonIndex<C, T>[] sign

/**
* Builds and returns a signer configuration map.
*
*
* @param signerIndexes
* signer configuration entries loaded from JSON
* @param theme
Expand Down Expand Up @@ -175,6 +186,13 @@ public SignerConfig getSignerConfig(String serviceName, String regionName) {
return signerConfig == null ? defaultSignerConfig : signerConfig;
}

/**
* @return the custom user agent template, if configured
*/
public String getUserAgentTemplate() {
return userAgentTemplate;
}

static InternalConfigJsonHelper loadfrom(URL url)
throws JsonParseException, JsonMappingException, IOException {
if (url == null)
Expand Down Expand Up @@ -213,14 +231,16 @@ static InternalConfig load() throws JsonParseException,
}
return new InternalConfig(config, configOverride);
}

// For debugging purposes
void dump() {
StringBuilder sb = new StringBuilder().append("defaultSignerConfig: ")
.append(defaultSignerConfig).append("\n")
.append("serviceRegionSigners: ").append(serviceRegionSigners)
.append("\n").append("regionSigners: ").append(regionSigners)
.append("\n").append("serviceSigners: ").append(serviceSigners);
.append("\n").append("serviceSigners: ").append(serviceSigners)
.append("\n").append("userAgentTemplate: ")
.append(userAgentTemplate);
log.debug(sb.toString());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2010-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
*
* http://aws.amazon.com/apache2.0
*
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
Expand All @@ -21,18 +21,22 @@
* marshaller/unmarshaller.
*/
class InternalConfigJsonHelper {

private SignerConfigJsonHelper defaultSigner;

// Implementation note:
// Internally use list instead of Map for ease of implementation to
// leverage on Jackson which supports recursive list of arbitrary pojos
// leverage on Jackson which supports recursive list of arbitrary pojos
// without the use of custom [un]marshallers. This is not the case for
// Map, which Jackson only supports the use of strings
// Map, which Jackson only supports the use of strings
// without custom [un]marshaller.
private JsonIndex<SignerConfigJsonHelper, SignerConfig>[] serviceSigners;
private JsonIndex<SignerConfigJsonHelper, SignerConfig>[] regionSigners;
private JsonIndex<SignerConfigJsonHelper, SignerConfig>[] serviceRegionSigners;
private JsonIndex<HttpClientConfigJsonHelper, HttpClientConfig>[] httpClients;

private String userAgentTemplate;

SignerConfigJsonHelper getDefaultSigner() {
return defaultSigner;
}
Expand Down Expand Up @@ -72,4 +76,12 @@ public JsonIndex<HttpClientConfigJsonHelper, HttpClientConfig>[] getHttpClients(
public void setHttpClients(JsonIndex<HttpClientConfigJsonHelper, HttpClientConfig> ... httpClients) {
this.httpClients = httpClients;
}

public String getUserAgentTemplate() {
return userAgentTemplate;
}

void setUserAgentTemplate(String userAgentTemplate) {
this.userAgentTemplate = userAgentTemplate;
}
}
Loading

0 comments on commit 35299b6

Please sign in to comment.