这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ public STSAssumeRoleSessionCredentialsProvider(String roleArn) {
securityTokenService = new AWSSecurityTokenServiceClient();
}

/**
* Constructs a new STSAssumeRoleSessionCredentialsProvider, which makes a
* request to the AWS Security Token Service (STS), uses the provided
* {@link #roleArn} to assume a role and then request short lived session
* credentials, which will then be returned by this class's
* {@link #getCredentials()} method.
* @param roleArn
* The AWS ARN of the Role to be assumed.
* @param clientConfiguration
* The AWS ClientConfiguration to use when making AWS API requests.
*/
public STSAssumeRoleSessionCredentialsProvider(String roleArn, ClientConfiguration clientConfiguration) {
this.roleArn = roleArn;
securityTokenService = new AWSSecurityTokenServiceClient(clientConfiguration);
}

/**
* Constructs a new STSAssumeRoleSessionCredentialsProvider, which will use
* the specified long lived AWS credentials to make a request to the AWS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;

Expand Down Expand Up @@ -86,6 +87,17 @@ public class BasicSimianArmyContext implements Monkey.Context {

private final String region;

private ClientConfiguration awsClientConfig = new ClientConfiguration();

/* If configured, the proxy to be used when making AWS API requests */
private final String proxyHost;

private final String proxyPort;

private final String proxyUsernaem;

private final String proxyPassword;

/** protected constructor as the Shell is meant to be subclassed. */
protected BasicSimianArmyContext(String... configFiles) {
eventReport = new LinkedList<Event>();
Expand All @@ -105,9 +117,23 @@ protected BasicSimianArmyContext(String... configFiles) {
secret = config.getStr("simianarmy.client.aws.secretKey");
region = config.getStrOrElse("simianarmy.client.aws.region", "us-east-1");

// Check for and configure optional proxy configuration
proxyHost = config.getStr("simianarmy.client.aws.proxyHost");
proxyPort = config.getStr("simianarmy.client.aws.proxyPort");
proxyUsernaem = config.getStr("simianarmy.client.aws.proxyUser");
proxyPassword = config.getStr("simianarmy.client.aws.proxyPassword");
if ((proxyHost != null) && (proxyPort != null)) {
awsClientConfig.setProxyHost(proxyHost);
awsClientConfig.setProxyPort(Integer.parseInt(proxyPort));
if ((proxyUsernaem != null) && (proxyPassword != null)) {
awsClientConfig.setProxyUsername(proxyUsernaem);
awsClientConfig.setProxyPassword(proxyPassword);
}
}

assumeRoleArn = config.getStr("simianarmy.client.aws.assumeRoleArn");
if (assumeRoleArn != null) {
this.awsCredentialsProvider = new STSAssumeRoleSessionCredentialsProvider(assumeRoleArn);
this.awsCredentialsProvider = new STSAssumeRoleSessionCredentialsProvider(assumeRoleArn, awsClientConfig);
}

// if credentials are set explicitly make them available to the AWS SDK
Expand Down Expand Up @@ -173,11 +199,12 @@ protected void createClient() {
}

/**
* Create the specific client within passed region, using the appropriate AWS credentials provider.
* Create the specific client within passed region, using the appropriate AWS credentials provider
* and client configuration.
* @param clientRegion
*/
protected void createClient(String clientRegion) {
this.client = new AWSClient(clientRegion, awsCredentialsProvider);
this.client = new AWSClient(clientRegion, awsCredentialsProvider, awsClientConfig);
setCloudClient(this.client);
}

Expand Down
93 changes: 79 additions & 14 deletions src/main/java/com/netflix/simianarmy/client/aws/AWSClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.netflix.simianarmy.client.aws;

import com.amazonaws.AmazonServiceException;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.autoscaling.AmazonAutoScalingClient;
import com.amazonaws.services.autoscaling.model.AutoScalingGroup;
Expand Down Expand Up @@ -116,6 +117,8 @@ public class AWSClient implements CloudClient {

private final AWSCredentialsProvider awsCredentialsProvider;

private final ClientConfiguration awsClientConfig;

private ComputeService jcloudsComputeService;

/**
Expand Down Expand Up @@ -153,6 +156,7 @@ public class AWSClient implements CloudClient {
public AWSClient(String region) {
this.region = region;
this.awsCredentialsProvider = null;
this.awsClientConfig = null;
}

/**
Expand All @@ -165,6 +169,35 @@ public AWSClient(String region) {
public AWSClient(String region, AWSCredentialsProvider awsCredentialsProvider) {
this.region = region;
this.awsCredentialsProvider = awsCredentialsProvider;
this.awsClientConfig = null;
}

/**
* The constructor allows you to provide your own AWS client configuration.
* @param region
* the region
* @param awsClientConfig
* the AWS client configuration
*/
public AWSClient(String region, ClientConfiguration awsClientConfig) {
this.region = region;
this.awsCredentialsProvider = null;
this.awsClientConfig = awsClientConfig;
}

/**
* The constructor allows you to provide your own AWS credentials provider and client config.
* @param region
* the region
* @param awsCredentialsProvider
* the AWS credentials provider
* @param awsClientConfig
* the AWS client configuration
*/
public AWSClient(String region, AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration awsClientConfig) {
this.region = region;
this.awsCredentialsProvider = awsCredentialsProvider;
this.awsClientConfig = awsClientConfig;
}

/**
Expand All @@ -183,10 +216,18 @@ public String region() {
*/
protected AmazonEC2 ec2Client() {
AmazonEC2 client;
if (awsCredentialsProvider == null) {
client = new AmazonEC2Client();
if (awsClientConfig == null) {
if (awsCredentialsProvider == null) {
client = new AmazonEC2Client();
} else {
client = new AmazonEC2Client(awsCredentialsProvider);
}
} else {
client = new AmazonEC2Client(awsCredentialsProvider);
if (awsCredentialsProvider == null) {
client = new AmazonEC2Client(awsClientConfig);
} else {
client = new AmazonEC2Client(awsCredentialsProvider, awsClientConfig);
}
}
client.setEndpoint("ec2." + region + ".amazonaws.com");
return client;
Expand All @@ -199,10 +240,18 @@ protected AmazonEC2 ec2Client() {
*/
protected AmazonAutoScalingClient asgClient() {
AmazonAutoScalingClient client;
if (awsCredentialsProvider == null) {
client = new AmazonAutoScalingClient();
if (awsClientConfig == null) {
if (awsCredentialsProvider == null) {
client = new AmazonAutoScalingClient();
} else {
client = new AmazonAutoScalingClient(awsCredentialsProvider);
}
} else {
client = new AmazonAutoScalingClient(awsCredentialsProvider);
if (awsCredentialsProvider == null) {
client = new AmazonAutoScalingClient(awsClientConfig);
} else {
client = new AmazonAutoScalingClient(awsCredentialsProvider, awsClientConfig);
}
}
client.setEndpoint("autoscaling." + region + ".amazonaws.com");
return client;
Expand All @@ -215,10 +264,18 @@ protected AmazonAutoScalingClient asgClient() {
*/
protected AmazonElasticLoadBalancingClient elbClient() {
AmazonElasticLoadBalancingClient client;
if (awsCredentialsProvider == null) {
client = new AmazonElasticLoadBalancingClient();
if (awsClientConfig == null) {
if (awsCredentialsProvider == null) {
client = new AmazonElasticLoadBalancingClient();
} else {
client = new AmazonElasticLoadBalancingClient(awsCredentialsProvider);
}
} else {
client = new AmazonElasticLoadBalancingClient(awsCredentialsProvider);
if (awsCredentialsProvider == null) {
client = new AmazonElasticLoadBalancingClient(awsClientConfig);
} else {
client = new AmazonElasticLoadBalancingClient(awsCredentialsProvider, awsClientConfig);
}
}
client.setEndpoint("elasticloadbalancing." + region + ".amazonaws.com");
return client;
Expand All @@ -231,10 +288,18 @@ protected AmazonElasticLoadBalancingClient elbClient() {
*/
public AmazonSimpleDB sdbClient() {
AmazonSimpleDB client;
if (awsCredentialsProvider == null) {
client = new AmazonSimpleDBClient();
if (awsClientConfig == null) {
if (awsCredentialsProvider == null) {
client = new AmazonSimpleDBClient();
} else {
client = new AmazonSimpleDBClient(awsCredentialsProvider);
}
} else {
client = new AmazonSimpleDBClient(awsCredentialsProvider);
if (awsCredentialsProvider == null) {
client = new AmazonSimpleDBClient(awsClientConfig);
} else {
client = new AmazonSimpleDBClient(awsCredentialsProvider, awsClientConfig);
}
}
// us-east-1 has special naming
// http://docs.amazonwebservices.com/general/latest/gr/rande.html#sdb_region
Expand Down Expand Up @@ -310,9 +375,9 @@ public List<LoadBalancerDescription> describeElasticLoadBalancers(String... name
}

/**
* Describe a set of specific ELBs.
* Describe a specific ELB.
*
* @param names the ELB names
* @param name the ELB names
* @return the ELBs
*/
public LoadBalancerAttributes describeElasticLoadBalancerAttributes(String name) {
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/client.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ simianarmy.client.aws.region = us-west-1
### Operate in Cloud Formation mode - the random suffix appended to Auto Scaling Group names is ignored
### (specify ASG names as usual with no suffix in chaos.properties)
#
#simianarmy.client.chaos.class=com.netflix.simianarmy.basic.chaos.CloudFormationChaosMonkey
#simianarmy.client.chaos.class=com.netflix.simianarmy.basic.chaos.CloudFormationChaosMonkey

# Use the following if a proxy is needed to connect to AWS APIs
# proxyHost and proxyPort are required to connect through a proxy, proxyUser and proxyPassword are optional
#simianarmy.client.aws.proxyHost=
#simianarmy.client.aws.proxyPort=
#simianarmy.client.aws.proxyUser=
#simianarmy.client.aws.proxyPassword=