Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTP proxy support and IAM capabilities #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -9,10 +9,14 @@

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.maven.settings.Proxy;
import org.slf4j.Logger;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.services.cloudformation.AmazonCloudFormation;
import com.amazonaws.services.cloudformation.AmazonCloudFormationAsyncClient;
Expand Down Expand Up @@ -54,10 +58,12 @@ public class CarrotCloudForm {

private final long waitBetweenAttempts;

private final List<String> awsCapabilities;

public CarrotCloudForm(final Logger logger, final String stackName,
final String stackTemplate, final Map<String, String> stackParams,
final long timeout, final AWSCredentials credentials,
final String endpoint) {
final String endpoint, List<String> awsCapabilities, final List<Proxy> proxies) {

this.logger = logger;

Expand All @@ -70,10 +76,12 @@ public CarrotCloudForm(final Logger logger, final String stackName,
this.timeout = timeout;

this.endpoint = endpoint;

this.awsCapabilities = awsCapabilities;

this.waitBetweenAttempts = 10; // query every 10s

this.amazonClient = newClient(); // keep last
this.amazonClient = newClient(proxies); // keep last

}

Expand Down Expand Up @@ -135,10 +143,35 @@ public void logParamList() {

}

private AmazonCloudFormation newClient() {
private AmazonCloudFormation newClient(final List<Proxy> proxies) {

ClientConfiguration config = new ClientConfiguration();
if (!proxies.isEmpty()) {
final Proxy proxy = proxies.get(0);
if (proxies.size() > 1) {
logger.warn(
"More than one proxy specified; using the first one [{}]",
proxy.getHost());
}
config.setProxyHost(proxy.getHost());
config.setProxyPort(proxy.getPort());
config.setProxyUsername(proxy.getUsername());
config.setProxyPassword(proxy.getPassword());
final String protocol = proxy.getProtocol();
if (null != protocol) {
config.setProtocol(Protocol.valueOf(protocol
.toUpperCase(Locale.ENGLISH)));
}
/*
* This setup ignores nonProxyHosts, unfortunately. However, the
* target of the HTTP requests is always going to be AWS's servers,
* and you probably wouldn't have specified that in nonProxyHosts anyway.
*/
}

final AmazonCloudFormation amazonClient = new AmazonCloudFormationAsyncClient(
final AmazonCloudFormationAsyncClient amazonClient = new AmazonCloudFormationAsyncClient(
credentials);
amazonClient.setConfiguration(config);

logger.info("stack endpoint : {}", endpoint);

Expand Down Expand Up @@ -226,6 +259,7 @@ public Stack stackCreate() throws Exception {
request.withStackName(name);
request.withParameters(paramList);
request.withTemplateBody(template);
request.setCapabilities(awsCapabilities);

amazonClient.createStack(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.carrotgarden.maven.aws.cfn;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
Expand Down Expand Up @@ -115,6 +116,15 @@ protected String stackEndpoint() {
return amazonEndpoint(stackEndpoint, stackEndpintFormat);
}


/**
* AWS CloudFormation capabilities. You must set this to include "CAPABILITY_IAM"
* if your stack creates IAM resources.
*
* @parameter
*/
protected List<String> capabilities;

//

protected Map<String, String> loadPluginProperties() throws Exception {
Expand Down Expand Up @@ -170,10 +180,10 @@ protected CarrotCloudForm newCloudFormation( //

final long stackTimeout = Util.safeNumber(getLog(), this.stackTimeout,
600);

final CarrotCloudForm formation = new CarrotCloudForm(logger,
stackName(), stackTemplate, stackParams, stackTimeout,
credentials, stackEndpoint());
credentials, stackEndpoint(), capabilities, settings().getProxies());

return formation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import static org.junit.Assert.*;

import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.maven.settings.Proxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -47,7 +49,8 @@ public void testStack() throws Exception {
//

final CarrotCloudForm formation = new CarrotCloudForm(logger, stackName,
stackTemplate, stackParams, timeout, credentials, null);
stackTemplate, stackParams, timeout, credentials, null,
Collections.<String>emptyList(), Collections.<Proxy>emptyList());

formation.stackCreate();

Expand Down