Permalink
Browse files

Optional credentials with latest AWS SDK, closes #11.

  • Loading branch information...
kimchy committed Jun 20, 2012
1 parent 97c776b commit 96a4e5de4657b8cf8ce42ffdc9c8ca52178beea2
@@ -52,7 +52,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.3.10</version>
<version>1.3.11</version>
<scope>compile</scope>
<exclusions>
<!-- We need to exclude httpclient, since it pulls the wrong version -->
@@ -21,7 +21,8 @@
import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.*;
import com.amazonaws.internal.StaticCredentialsProvider;
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.AmazonEC2Client;
import org.elasticsearch.ElasticSearchException;
@@ -70,13 +71,6 @@ public synchronized AmazonEC2 client() {
String account = componentSettings.get("access_key", settings.get("cloud.account"));
String key = componentSettings.get("secret_key", settings.get("cloud.key"));
if (account == null) {
throw new ElasticSearchIllegalArgumentException("No aws access_key defined for ec2 discovery");
}
if (key == null) {
throw new ElasticSearchIllegalArgumentException("No aws secret_key defined for ec2 discovery");
}
String proxyHost = componentSettings.get("proxy_host");
if (proxyHost != null) {
String portString = componentSettings.get("proxy_port", "80");
@@ -89,7 +83,21 @@ public synchronized AmazonEC2 client() {
clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort);
}
this.client = new AmazonEC2Client(new BasicAWSCredentials(account, key), clientConfiguration);
AWSCredentialsProvider credentials;
if (account == null && key == null) {
credentials = new AWSCredentialsProviderChain(
new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
new InstanceProfileCredentialsProvider()
);
} else {
credentials = new AWSCredentialsProviderChain(
new StaticCredentialsProvider(new BasicAWSCredentials(account, key))
);
}
this.client = new AmazonEC2Client(credentials, clientConfiguration);
if (componentSettings.get("ec2.endpoint") != null) {
client.setEndpoint(componentSettings.get("ec2.endpoint"));
@@ -21,7 +21,8 @@
import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.*;
import com.amazonaws.internal.StaticCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import org.elasticsearch.ElasticSearchException;
@@ -62,13 +63,6 @@ public synchronized AmazonS3 client() {
String account = componentSettings.get("access_key", settings.get("cloud.account"));
String key = componentSettings.get("secret_key", settings.get("cloud.key"));
if (account == null) {
throw new ElasticSearchIllegalArgumentException("No s3 access_key defined for s3 gateway");
}
if (key == null) {
throw new ElasticSearchIllegalArgumentException("No s3 secret_key defined for s3 gateway");
}
String proxyHost = componentSettings.get("proxy_host");
if (proxyHost != null) {
String portString = componentSettings.get("proxy_port", "80");
@@ -81,7 +75,20 @@ public synchronized AmazonS3 client() {
clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort);
}
this.client = new AmazonS3Client(new BasicAWSCredentials(account, key), clientConfiguration);
AWSCredentialsProvider credentials;
if (account == null && key == null) {
credentials = new AWSCredentialsProviderChain(
new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
new InstanceProfileCredentialsProvider()
);
} else {
credentials = new AWSCredentialsProviderChain(
new StaticCredentialsProvider(new BasicAWSCredentials(account, key))
);
}
this.client = new AmazonS3Client(credentials, clientConfiguration);
if (componentSettings.get("s3.endpoint") != null) {
client.setEndpoint(componentSettings.get("s3.endpoint"));

0 comments on commit 96a4e5d

Please sign in to comment.