Search in sources :

Example 6 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.

the class ParameterParseTests method parseMap.

@Test
public void parseMap() throws IOException {
    ParameterProvider parameterProvider = Mockito.mock(ParameterProvider.class);
    Mockito.when(parameterProvider.getParams()).thenReturn(new HashMap<String, Object>() {

        {
            put("foo", "true");
            put("baz", false);
            put("bar", 25);
        }
    });
    Collection<Parameter> parameters = ParameterParser.parse(new FilePath(temporaryFolder.newFolder()), parameterProvider);
    Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("foo").withParameterValue("true"), new Parameter().withParameterKey("baz").withParameterValue("false"), new Parameter().withParameterKey("bar").withParameterValue("25"));
}
Also used : FilePath(hudson.FilePath) ParameterProvider(de.taimos.pipeline.aws.cloudformation.ParameterProvider) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Test(org.junit.Test)

Example 7 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.

the class YAMLParameterFileParserTests method parseParameterCollection.

@Test
public void parseParameterCollection() throws IOException {
    YAMLParameterFileParser parser = new YAMLParameterFileParser();
    String json = "bar:\n  - foo1\n  - foo2";
    Collection<Parameter> parameters = parser.parseParams(new StringInputStream(json));
    Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("bar").withParameterValue("foo1,foo2"));
}
Also used : StringInputStream(com.amazonaws.util.StringInputStream) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Test(org.junit.Test)

Example 8 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.

the class JSONParameterFileParser method parseParams.

@Override
public Collection<Parameter> parseParams(InputStream fileContent) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode tree = mapper.readTree(fileContent);
    Collection<Parameter> parameters = new ArrayList<>();
    if (tree instanceof ArrayNode) {
        ArrayNode jsonNodes = (ArrayNode) tree;
        for (JsonNode node : jsonNodes) {
            Parameter param = new Parameter();
            param.withParameterKey(node.get("ParameterKey").asText());
            if (node.has("ParameterValue")) {
                param.withParameterValue(node.get("ParameterValue").asText());
            }
            if (node.has("UsePreviousValue")) {
                param.withUsePreviousValue(node.get("UsePreviousValue").booleanValue());
            }
            parameters.add(param);
        }
    }
    return parameters;
}
Also used : ArrayList(java.util.ArrayList) Parameter(com.amazonaws.services.cloudformation.model.Parameter) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.

the class YAMLParameterFileParser method parseParams.

@Override
public Collection<Parameter> parseParams(InputStream fileContent) throws IOException {
    Yaml yaml = new Yaml();
    @SuppressWarnings("unchecked") Map<String, Object> parse = yaml.load(new InputStreamReader(fileContent, Charsets.UTF_8));
    Collection<Parameter> parameters = new ArrayList<>();
    for (Map.Entry<String, Object> entry : parse.entrySet()) {
        Object value = entry.getValue();
        if (value instanceof Collection) {
            String val = Joiner.on(",").join((Collection) value);
            parameters.add(new Parameter().withParameterKey(entry.getKey()).withParameterValue(val));
        } else {
            parameters.add(new Parameter().withParameterKey(entry.getKey()).withParameterValue(value.toString()));
        }
    }
    return parameters;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Collection(java.util.Collection) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml)

Example 10 with Parameter

use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.

the class ParameterParserTest method shouldParseYAML.

@Test
public void shouldParseYAML() throws Exception {
    YAMLParameterFileParser parser = new YAMLParameterFileParser();
    Collection<Parameter> parameters = parser.parseParams(this.getClass().getResourceAsStream("/params.yaml"));
    Parameter[] array = parameters.toArray(new Parameter[0]);
    Assert.assertEquals(2, array.length);
    Parameter param1 = array[0];
    Assert.assertEquals("Param1", param1.getParameterKey());
    Assert.assertEquals("Value1", param1.getParameterValue());
    Parameter param2 = array[1];
    Assert.assertEquals("Param2", param2.getParameterKey());
    Assert.assertEquals("Val2a,Val2b", param2.getParameterValue());
}
Also used : Parameter(com.amazonaws.services.cloudformation.model.Parameter) YAMLParameterFileParser(de.taimos.pipeline.aws.cloudformation.parser.YAMLParameterFileParser) Test(org.junit.Test)

Aggregations

Parameter (com.amazonaws.services.cloudformation.model.Parameter)85 Test (org.junit.Test)79 Context (de.widdix.awscftemplates.Context)66 ACloudFormationTest (de.widdix.awscftemplates.ACloudFormationTest)60 HttpResponse (org.apache.http.HttpResponse)19 KeyPair (com.amazonaws.services.ec2.model.KeyPair)5 StringInputStream (com.amazonaws.util.StringInputStream)4 ArrayList (java.util.ArrayList)4 DescribeContainerInstancesRequest (com.amazonaws.services.ecs.model.DescribeContainerInstancesRequest)3 DescribeContainerInstancesResult (com.amazonaws.services.ecs.model.DescribeContainerInstancesResult)3 ListContainerInstancesRequest (com.amazonaws.services.ecs.model.ListContainerInstancesRequest)3 ListContainerInstancesResult (com.amazonaws.services.ecs.model.ListContainerInstancesResult)3 ParameterProvider (de.taimos.pipeline.aws.cloudformation.ParameterProvider)3 FilePath (hudson.FilePath)3 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)2 TaskListener (hudson.model.TaskListener)2 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)2 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Change (com.amazonaws.services.cloudformation.model.Change)1