Java 类com.amazonaws.services.cloudformation.model.Parameter 实例源码

项目:aws-ec2-ssh    文件:TestShowcase.java   
@Test
public void testCentOS() throws Exception {
    final String stackName = "showcase-" + this.random8String();
    final String userName = "user-" + this.random8String();
    try {
        final User user = this.createUser(userName);
        try {
            this.createStack(stackName,
                    "showcase.yaml",
                    new Parameter().withParameterKey("VPC").withParameterValue(this.getDefaultVPC().getVpcId()),
                    new Parameter().withParameterKey("Subnet").withParameterValue(this.getDefaultSubnets().get(0).getSubnetId()),
                    new Parameter().withParameterKey("OS").withParameterValue("CentOS")
            );
            final String host = this.getStackOutputValue(stackName, "PublicName");
            this.probeSSH(host, user);
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteUser(userName);
    }
}
项目:aws-ec2-ssh    文件:TestShowcase.java   
@Test
public void testRHEL() throws Exception {
    final String stackName = "showcase-" + this.random8String();
    final String userName = "user-" + this.random8String();
    try {
        final User user = this.createUser(userName);
        try {
            this.createStack(stackName,
                    "showcase.yaml",
                    new Parameter().withParameterKey("VPC").withParameterValue(this.getDefaultVPC().getVpcId()),
                    new Parameter().withParameterKey("Subnet").withParameterValue(this.getDefaultSubnets().get(0).getSubnetId()),
                    new Parameter().withParameterKey("OS").withParameterValue("RHEL")
            );
            final String host = this.getStackOutputValue(stackName, "PublicName");
            this.probeSSH(host, user);
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteUser(userName);
    }
}
项目:aws-ec2-ssh    文件:TestShowcase.java   
@Test
public void testSUSELinuxEnterpriseServer() throws Exception {
    final String stackName = "showcase-" + this.random8String();
    final String userName = "user-" + this.random8String();
    try {
        final User user = this.createUser(userName);
        try {
            this.createStack(stackName,
                    "showcase.yaml",
                    new Parameter().withParameterKey("VPC").withParameterValue(this.getDefaultVPC().getVpcId()),
                    new Parameter().withParameterKey("Subnet").withParameterValue(this.getDefaultSubnets().get(0).getSubnetId()),
                    new Parameter().withParameterKey("OS").withParameterValue("SUSELinuxEnterpriseServer")
            );
            final String host = this.getStackOutputValue(stackName, "PublicName");
            this.probeSSH(host, user);
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteUser(userName);
    }
}
项目:aws-ec2-ssh    文件:TestShowcase.java   
@Test
public void testUbuntu() throws Exception {
    final String stackName = "showcase-" + this.random8String();
    final String userName = "user-" + this.random8String();
    try {
        final User user = this.createUser(userName);
        try {
            this.createStack(stackName,
                    "showcase.yaml",
                    new Parameter().withParameterKey("VPC").withParameterValue(this.getDefaultVPC().getVpcId()),
                    new Parameter().withParameterKey("Subnet").withParameterValue(this.getDefaultSubnets().get(0).getSubnetId()),
                    new Parameter().withParameterKey("OS").withParameterValue("Ubuntu")
            );
            final String host = this.getStackOutputValue(stackName, "PublicName");
            this.probeSSH(host, user);
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteUser(userName);
    }
}
项目:aws-ec2-ssh    文件:TestShowcase.java   
@Test
public void testAmazonLinux2() throws Exception {
    final String stackName = "showcase-" + this.random8String();
    final String userName = "user-" + this.random8String();
    try {
        final User user = this.createUser(userName);
        try {
            this.createStack(stackName,
                    "showcase.yaml",
                    new Parameter().withParameterKey("VPC").withParameterValue(this.getDefaultVPC().getVpcId()),
                    new Parameter().withParameterKey("Subnet").withParameterValue(this.getDefaultSubnets().get(0).getSubnetId()),
                    new Parameter().withParameterKey("OS").withParameterValue("AmazonLinux2")
            );
            final String host = this.getStackOutputValue(stackName, "PublicName");
            this.probeSSH(host, user);
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteUser(userName);
    }
}
项目:aws-ec2-ssh    文件:TestShowcase.java   
@Test
public void testDefaultAmazonLinux() throws Exception {
    final String stackName = "showcase-" + this.random8String();
    final String userName = "user-" + this.random8String();
    try {
        final User user = this.createUser(userName);
        try {
            this.createStack(stackName,
                    "showcase.yaml",
                    new Parameter().withParameterKey("VPC").withParameterValue(this.getDefaultVPC().getVpcId()),
                    new Parameter().withParameterKey("Subnet").withParameterValue(this.getDefaultSubnets().get(0).getSubnetId())
            );
            final String host = this.getStackOutputValue(stackName, "PublicName");
            this.probeSSH(host, user);
        } finally {
            this.deleteStack(stackName);
        }
    } finally {
        this.deleteUser(userName);
    }
}
项目:aws-cf-templates    文件:TestVPCEndpointDynamoDB.java   
@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String endpointStackName = "vpc-endpoint-dynamodb-" + this.random8String();
    final String classB = "10";
    try {
        this.createStack(vpcStackName,
                "vpc/vpc-2azs.yaml",
                new Parameter().withParameterKey("ClassB").withParameterValue(classB)
        );
        try {
            this.createStack(endpointStackName,
                    "vpc/vpc-endpoint-dynamodb.yaml",
                    new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName)
            );
            // TODO how can we check if this stack works?
        } finally {
            this.deleteStack(endpointStackName);
        }
    } finally {
        this.deleteStack(vpcStackName);
    }
}
项目:aws-cf-templates    文件:TestVPCNatGateway.java   
@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String natStackName = "vpc-nat-gateway-" + this.random8String();
    final String classB = "10";
    try {
        this.createStack(vpcStackName,
                "vpc/vpc-2azs.yaml",
                new Parameter().withParameterKey("ClassB").withParameterValue(classB)
        );
        try {
            this.createStack(natStackName,
                    "vpc/vpc-nat-gateway.yaml",
                    new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName)
            );
            this.testVPCSubnetInternetAccess(vpcStackName, "SubnetAPrivate");
        } finally {
            this.deleteStack(natStackName);
        }
    } finally {
        this.deleteStack(vpcStackName);
    }
}
项目:aws-cf-templates    文件:TestVPC4AZs.java   
@Test
public void test() {
    final String stackName = "vpc-4azs-" + this.random8String();
    try {
        this.createStack(stackName,
                "vpc/vpc-4azs.yaml",
                new Parameter().withParameterKey("ClassB").withParameterValue("10")
        );
        this.testVPCSubnetInternetAccess(stackName, "SubnetAPublic");
        this.testVPCSubnetInternetAccess(stackName, "SubnetBPublic");
        this.testVPCSubnetInternetAccess(stackName, "SubnetCPublic");
        this.testVPCSubnetInternetAccess(stackName, "SubnetDPublic");
    } finally {
        this.deleteStack(stackName);
    }
}
项目:aws-cf-templates    文件:TestVPCEndpointS3.java   
@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String endpointStackName = "vpc-endpoint-s3-" + this.random8String();
    final String classB = "10";
    try {
        this.createStack(vpcStackName,
                "vpc/vpc-2azs.yaml",
                new Parameter().withParameterKey("ClassB").withParameterValue(classB)
        );
        try {
            this.createStack(endpointStackName,
                    "vpc/vpc-endpoint-s3.yaml",
                    new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName)
            );
            // TODO how can we check if this stack works?
        } finally {
            this.deleteStack(endpointStackName);
        }
    } finally {
        this.deleteStack(vpcStackName);
    }
}
项目:cfnassist    文件:CreateKeyPairAction.java   
@Override
public void invoke(FacadeFactory factory, ProjectAndEnv projectAndEnv, Collection<Parameter> cfnParams,
                   Collection<Parameter> artifacts, String... argument) throws IOException, InterruptedException,
        CfnAssistException, MissingArgumentException {
    AwsFacade facade = factory.createFacade();

    String filename;
    if (argument==null) {
        String home = System.getenv("HOME");
        String keypairName = format("%s_%s", projectAndEnv.getProject(), projectAndEnv.getEnv());
        filename = format("%s/.ssh/%s.pem", home, keypairName);
    } else {
        filename = argument[0];
    }

    KeyPair keyPair = facade.createKeyPair(projectAndEnv, factory.getSavesFile(), filename);
    System.out.println(format("Created key %s with fingerprint %s", keyPair.getKeyName(),
            keyPair.getKeyFingerprint()));
}
项目:cfnassist    文件:ParameterFactory.java   
public Collection<Parameter> createRequiredParameters(ProjectAndEnv projAndEnv,
                                                         Collection<Parameter> userParameters,
                                                         List<TemplateParameter> declaredParameters,
                                                         ProvidesZones providesZones)
        throws InvalidStackParameterException,
        IOException, CannotFindVpcException {

    Collection<Parameter> result  = new LinkedList<>();
    result.addAll(userParameters);

    checkNoClashWithBuiltInParameters(result);
    for(PopulatesParameters populator : populators) {
        populator.addParameters(result, declaredParameters, projAndEnv, providesZones);
    }

    logAllParameters(result, declaredParameters);
    return result;
}
项目:cfnassist    文件:AutoDiscoverParams.java   
private List<Parameter> fetchAutopopulateParametersFor(ProjectAndEnv projectAndEnv, List<TemplateParameter> declaredParameters, Map<String, AvailabilityZone> zones) throws IOException, InvalidStackParameterException, CannotFindVpcException {
    logger.info(String.format("Discover and populate parameters for %s and %s", templateFile.getAbsolutePath(), projectAndEnv));
    List<Parameter> matches = new LinkedList<>();
    for(TemplateParameter templateParam : declaredParameters) {
        String name = templateParam.getParameterKey();
        if (isBuiltInParamater(name))
        {
            continue;
        }
        logger.info("Checking if parameter should be auto-populated from an existing resource, param name is " + name);
        String description = templateParam.getDescription();
        if (shouldPopulateFor(description)) {
            populateParameter(projectAndEnv, matches, name, description, declaredParameters, zones);
        }
    }
    return matches;
}
项目:cfnassist    文件:AutoDiscoverParams.java   
private void populateParamForZone(Collection<Parameter> results,
                                  List<TemplateParameter> declaredParameters,
                                  Map<String, AvailabilityZone> zones, String parameterName,
                                  String parameterDescription) {
    logger.info(String.format("Check parameter for zone %s and target %s", parameterName, parameterDescription));
    String target = parameterDescription.replaceFirst(PopulatesParameters.CFN_TAG_ZONE, "").toLowerCase();
    logger.debug("Check for zone " + target);
    if (zones.containsKey(target)) {
        String zoneName = zones.get(target).getZoneName();
        declaredParameters.stream().filter(declaredParameter -> declaredParameter.getParameterKey().equals(parameterName)).
                forEach(declaredParameter -> {
                    addParameterTo(results, declaredParameters, parameterName, zoneName);
                    logger.info(String.format("Adding zone parameter %s with value %s", parameterName, zoneName));
                });
    } else {
        logger.error("Could not find matching zone for target " + target);
    }
}
项目:cfnassist    文件:PopulatesParameters.java   
protected void addParameterTo(Collection<Parameter> parameters, List<TemplateParameter> declared, String parameterName, String parameterValue) {
    boolean isDeclared = false;
    for(TemplateParameter declaration : declared) {
        isDeclared = (declaration.getParameterKey().equals(parameterName));
        if (isDeclared==true) break;
    }
    if (!isDeclared) {
        logger.info(String.format("Not populating parameter %s as it is not declared in the json file", parameterName));
    } else {
        logger.info(String.format("Setting %s parameter to %s", parameterName, parameterValue));
        Parameter parameter = new Parameter();
        parameter.setParameterKey(parameterName);
        parameter.setParameterValue(parameterValue);
        parameters.add(parameter);
    }
}
项目:cfnassist    文件:DiagramsElement.java   
@Override
public void execute(FacadeFactory factory, ProjectAndEnv projectAndEnv,
        Collection<Parameter> cfnParams, Collection<Parameter> artifacts)
        throws IOException, InterruptedException,
        CfnAssistException, CommandLineException, MissingArgumentException {
    String path = target.getAbsolutePath();

    if (!target.isDirectory()) {
        throw new BuildException(
                String.format("Target %s was not a directory, please provide a directory for the diagrams to be saved into", path));
    }

    CreateDiagramAction action = new CreateDiagramAction();

    action.validate(projectAndEnv, cfnParams, artifacts, path);
    action.invoke(factory, projectAndEnv, cfnParams, artifacts, path);

}
项目:cfnassist    文件:TemplatesElement.java   
@Override
public void execute(FacadeFactory factory, ProjectAndEnv projectAndEnv, Collection<Parameter> cfnParams, Collection<Parameter> artifacts) 
        throws IOException, InterruptedException, CfnAssistException,
        CommandLineException, MissingArgumentException {
    String absolutePath = target.getAbsolutePath();
    CommandLineAction actionToInvoke = null;
    if (target.isDirectory()) {
        actionToInvoke = new DirAction();
    } else if (target.isFile()) {
        actionToInvoke = new FileAction();
    } 

    if (actionToInvoke==null) {
        throw new BuildException("Unable to action on path, expect file or folder, path was: " + absolutePath);
    } 
    actionToInvoke.validate(projectAndEnv, cfnParams, artifacts, absolutePath);
    actionToInvoke.invoke(factory, projectAndEnv, cfnParams, artifacts, absolutePath);      
}
项目:cfnassist    文件:ArtifactUploader.java   
private Parameter processArtifact(Parameter artifact) {
    String fullFilePath = artifact.getParameterValue();
    File item = FileUtils.getFile(fullFilePath);

    URL url;
    if (item.isDirectory()) {
        for (File file : item.listFiles()) {
            if (file.isFile()) {
                URL fileUrl = uploadItem(file);
                logger.info(String.format("Uploaded %s at URL %s", file.getAbsolutePath(), fileUrl));
            } else {
                logger.warn("Skipped item " + file.getAbsolutePath());
            }
        }
        url = s3Client.getUrl(bucketName, buildNumber.toString());
    } else {
        url = uploadItem(item);
    }
    logger.info(String.format("Uploaded %s at URL %s", item.getAbsolutePath(), url));
    return new Parameter().withParameterKey(artifact.getParameterKey()).withParameterValue(url.toString());
}
项目:cfnassist    文件:TestArtifactUploader.java   
@Test
public void canDeleteArtifactsFromS3() {
    List<Parameter> arts = new LinkedList<>();

    // any files would do here
    Parameter artA = new Parameter().withParameterKey("urlA").withParameterValue(FilesForTesting.INSTANCE); 
    arts.add(artA); 
    ArtifactUploader uploader = new ArtifactUploader(s3Client, EnvironmentSetupForTests.BUCKET_NAME, BUILD_NUMBER);
    uploader.uploadArtifacts(arts); 

    // check upload actually happened   
    List<S3ObjectSummary> objectSummaries = EnvironmentSetupForTests.getBucketObjects(s3Client);
    assertTrue(EnvironmentSetupForTests.isContainedIn(objectSummaries, KEY_A));

    uploader.delete("instance.json");
    objectSummaries = EnvironmentSetupForTests.getBucketObjects(s3Client);
    assertFalse(EnvironmentSetupForTests.isContainedIn(objectSummaries, KEY_A));
}
项目:cfnassist    文件:EnvironmentSetupForTests.java   
public static StackNameAndId createTemporarySimpleStack(AmazonCloudFormation cfnClient, String vpcId, String arn) throws IOException {
    CreateStackRequest createStackRequest = new CreateStackRequest();
    createStackRequest.setStackName(TEMPORARY_STACK);
    File file = new File(FilesForTesting.SIMPLE_STACK);
    createStackRequest.setTemplateBody(FileUtils.readFileToString(file , Charset.defaultCharset()));
    Collection<Parameter> parameters = new LinkedList<>();
    parameters.add(createParam("env", EnvironmentSetupForTests.ENV));
    parameters.add(createParam("vpc", vpcId));
    if (!arn.isEmpty()) {
        Collection<String> notificationARNs = new LinkedList<>();
        notificationARNs.add(arn);
        logger.debug("Adding arn subscription "+ arn);
        createStackRequest.setNotificationARNs(notificationARNs);
    }
    createStackRequest.setParameters(parameters);
    CreateStackResult result = cfnClient.createStack(createStackRequest);
    return new StackNameAndId(TEMPORARY_STACK, result.getStackId());
}
项目:cfnassist    文件:UpdateStackExpectations.java   
protected StackNameAndId setUpdateExpectations(String stackName, String filename,
                                               List<TemplateParameter> templateParameters,
                                               Collection<Parameter> parameters)
        throws CfnAssistException, InterruptedException, IOException {
    String stackId = "stackId";
    Stack stack = new Stack().withStackId(stackId);
    StackNameAndId stackNameAndId = new StackNameAndId(stackName, stackId);

    String contents = EnvironmentSetupForTests.loadFile(filename);
    EasyMock.expect(vpcRepository.getCopyOfVpc(projectAndEnv)).andReturn(new Vpc().withVpcId(VPC_ID));
    EasyMock.expect(cfnRepository.validateStackTemplate(contents)).andReturn(templateParameters);

    EasyMock.expect(cfnRepository.updateStack(contents, parameters, monitor, stackName)).andReturn(stackNameAndId);
    EasyMock.expect(monitor.waitForUpdateFinished(stackNameAndId)).andReturn(StackStatus.UPDATE_COMPLETE.toString());
    EasyMock.expect(cfnRepository.updateSuccess(stackNameAndId)).andReturn(stack);
    EasyMock.expect(cloudRepository.getZones()).andReturn(zones);
    return stackNameAndId;
}
项目:cfnassist    文件:TestAwsFacade.java   
private void checkParameterCannotBePassed(String parameterName)
        throws IOException,
        CfnAssistException, InterruptedException {
    Parameter parameter = new Parameter();
    parameter.setParameterKey(parameterName);
    parameter.setParameterValue("test");

    Collection<Parameter> parameters = new HashSet<>();
    parameters.add(parameter);

    try {
        aws.applyTemplate(new File(FilesForTesting.SIMPLE_STACK), projectAndEnv, parameters);
        fail("Should have thrown exception");
    }
    catch (InvalidStackParameterException exception) {
        // expected
    }
}
项目:cfnassist    文件:TestAwsFacadeUpdateStacks.java   
@Test
public void voidShouldUpdateAnExistingStackNoParams() throws IOException, CfnAssistException, InterruptedException {
    String filename = FilesForTesting.SUBNET_STACK_DELTA;
    String stackName = "CfnAssistTestsubnet";

    List<TemplateParameter> templateParameters = new LinkedList<>();
    templateParameters.add(new TemplateParameter().withParameterKey("stackname").withDefaultValue("subnet"));
    Collection<Parameter> parameters = new LinkedList<>();

       StackNameAndId stackNameAndId = setUpdateExpectations(stackName, filename, templateParameters, parameters);

    replayAll();
    StackNameAndId result = aws.applyTemplate(filename, projectAndEnv);
    assertEquals(stackNameAndId, result);
    verifyAll();    
}
项目:cfnassist    文件:TestAwsFacadeUpdateStacks.java   
@Test
public void voidShouldUpdateAnExistingStackWithBuiltInParams() throws IOException, CfnAssistException, InterruptedException {
    String filename = FilesForTesting.SUBNET_STACK_DELTA;
    String stackName = "CfnAssistTestsubnet";

    List<TemplateParameter> templateParameters = new LinkedList<>();
    templateParameters.add(new TemplateParameter().withParameterKey("stackname").withDefaultValue("subnet"));
    templateParameters.add(new TemplateParameter().withParameterKey("env").withDefaultValue(projectAndEnv.getEnv()));
    templateParameters.add(new TemplateParameter().withParameterKey("vpc").withDefaultValue(VPC_ID));

    Collection<Parameter> creationParameters = new LinkedList<>();
    TestAwsFacadeCreatesStacks.addParam(creationParameters, "env", projectAndEnv.getEnv());
    TestAwsFacadeCreatesStacks.addParam(creationParameters, "vpc", VPC_ID);

       StackNameAndId stackNameAndId = setUpdateExpectations(stackName, filename, templateParameters, creationParameters);

    replayAll();
    StackNameAndId result = aws.applyTemplate(filename, projectAndEnv);
    assertEquals(stackNameAndId, result);
    verifyAll();    
}
项目:cfnassist    文件:TestAwsFacadeUpdateStacks.java   
@Test
public void voidShouldUpdateAnExistingStackUserParams() throws IOException, CfnAssistException, InterruptedException {
    String filename = FilesForTesting.SUBNET_STACK_DELTA;
    String stackName = "CfnAssistTestsubnet";

    List<TemplateParameter> templateParameters = new LinkedList<>();
    templateParameters.add(new TemplateParameter().withParameterKey("stackname").withDefaultValue("subnet"));
    Collection<Parameter> userParameters  = new LinkedList<>();
    Collection<Parameter> creationParameters = new LinkedList<>();
    TestAwsFacadeCreatesStacks.addParam(userParameters, "userKey", "value");
    TestAwsFacadeCreatesStacks.addParam(creationParameters, "userKey", "value");

       StackNameAndId stackNameAndId = setUpdateExpectations(stackName, filename, templateParameters, creationParameters);

    replayAll();

    StackNameAndId result = aws.applyTemplate(new File(filename), projectAndEnv, userParameters);
    assertEquals(stackNameAndId, result);
    verifyAll();    
}
项目:cfnassist    文件:TestCommandLineActions.java   
@Test
public void shouldUploadArtifacts() throws MissingArgumentException, CfnAssistException, InterruptedException {
    Integer buildNumber = 9987;
    Collection<Parameter> arts = new LinkedList<>();
    arts.add(new Parameter().withParameterKey("art1").withParameterValue(FilesForTesting.ACL));
    arts.add(new Parameter().withParameterKey("art2").withParameterValue(FilesForTesting.SUBNET_STACK));
    List<Parameter> uploaded = new LinkedList<>();

    factory.setProject(EnvironmentSetupForTests.PROJECT);

    projectAndEnv.addBuildNumber(buildNumber);
    EasyMock.expect(factory.createArtifactUploader(projectAndEnv)).andReturn(artifactUploader);
    EasyMock.expect(artifactUploader.uploadArtifacts(arts)).andReturn(uploaded);

    validate(CLIArgBuilder.uploadArtifacts(buildNumber));
}
项目:cfnassist    文件:TestEnvVarParams.java   
@Test
public void shouldPickUpVariableFromEnvironmentIfDeclaredInTemplate() throws CannotFindVpcException, IOException, InvalidStackParameterException {

    List<Parameter> results = new LinkedList<>();
    List<TemplateParameter> declaredParameters = new LinkedList<>();
    declaredParameters.add(new TemplateParameter().
            withDescription("::ENV").
            withParameterKey("testEnvVar"));

    envVarParams.addParameters(results , declaredParameters, projAndEnv, this);

    assertEquals(1, results.size());
    Parameter firstResult = results.get(0);
    assertEquals("testValue", firstResult.getParameterValue());
    assertEquals("testEnvVar", firstResult.getParameterKey());  
}
项目:cfnassist    文件:TestEnvVarParams.java   
@Test
public void shouldThrowIfEnvVariableIsNotFound() throws CannotFindVpcException, IOException {

    List<Parameter> results = new LinkedList<>();
    List<TemplateParameter> declaredParameters = new LinkedList<>();
    declaredParameters.add(new TemplateParameter().
            withDescription("::ENV").
            withParameterKey("envVarShouldNotExist"));
    try {
        envVarParams.addParameters(results , declaredParameters, projAndEnv, this);
        fail("should have thrown");
    }
    catch(InvalidStackParameterException expected) {
        // expected
    }
}
项目:cfnassist    文件:TestAwsFacadeDeltaApplicationAndRollbacks.java   
@Test
public void shouldApplyFilesInAFolderWithUpdate() throws CfnAssistException, IOException, InterruptedException {
    List<File> allFiles = loadFiles(FilesForTesting.ORDERED_SCRIPTS_WITH_UPDATES_FOLDER.toFile());

    EasyMock.expect(cloudRepository.getZones()).andReturn(new HashMap<>());
    EasyMock.expect(vpcRepository.getVpcIndexTag(projectAndEnv)).andReturn("0");
    // first file - no parameters needed
    setExpectationsForValidationPass(allFiles);

    LinkedList<Parameter> cfnParams = new LinkedList<>();

    List<TemplateParameter> templateParameters = Collections.singletonList(new TemplateParameter().
            withParameterKey(AwsFacade.PARAMETER_STACKNAME).withDefaultValue("01createSubnet"));
    // processing pass
    setExpectationsForFile(1, allFiles.get(0), new LinkedList<>());
    setUpdateExpectations("CfnAssistTest01createSubnet", allFiles.get(1).getAbsolutePath(), templateParameters,
            cfnParams);
    vpcRepository.setVpcIndexTag(projectAndEnv, "2");
    EasyMock.expectLastCall();

    replayAll();
    ArrayList<StackNameAndId> result = aws.applyTemplatesFromFolder(FilesForTesting.ORDERED_SCRIPTS_WITH_UPDATES_FOLDER.toString(),
            projectAndEnv, cfnParams);
    verifyAll();
    assertEquals(2, result.size());
}
项目:aws-sam-gradle    文件:AwsSamDeployPlugin.java   
private ReplacePlaceholerTask createUpdateSwaggerTask(File swaggerDefinition) {
    final ReplacePlaceholerTask task = createTask("updateSwagger", ReplacePlaceholerTask.class);
    final AwsMetadataService awsMetadataService = new AwsMetadataService(config);
    task.parameters = asList(
            new Parameter().withParameterKey("region").withParameterValue(config.getActiveRegion().getName()),
            new Parameter().withParameterKey("accountId").withParameterValue(awsMetadataService.getAccountId()));
    task.input = swaggerDefinition;
    task.output = new File(project.getBuildDir(), task.input.getName());
    return task;
}
项目:aws-sam-gradle    文件:DeployService.java   
private String updateTemplateBody(String templateBody, String codeUri, String swaggerDefinitionUri) {
    final Collection<Parameter> parameters = new ArrayList<>();
    parameters.add(new Parameter().withParameterKey("CodeUri").withParameterValue(Objects.requireNonNull(codeUri)));
    parameters.add(new Parameter().withParameterKey("stage").withParameterValue(config.getStageName()));
    if (swaggerDefinitionUri != null) {
        parameters.add(new Parameter().withParameterKey("DefinitionUri").withParameterValue(swaggerDefinitionUri));
    }
    final String newTemplateBody = templateService.replaceParameters(templateBody, parameters);
    templateService.writeFile(newTemplateBody, config.getBuildDir().resolve("updated-template.yaml"));
    return newTemplateBody;
}
项目:aws-sam-gradle    文件:CloudformationService.java   
public String createChangeSet(String changeSetName, String stackName, ChangeSetType changeSetType,
        String templateBody, Collection<Parameter> parameters) {
    LOG.info("Creating change set for stack {} with name {}, type {} and parameters {}", stackName, changeSetName,
            changeSetType, parameters);
    final CreateChangeSetRequest changeSetRequest = new CreateChangeSetRequest() //
            .withCapabilities(Capability.CAPABILITY_IAM) //
            .withStackName(stackName) //
            .withDescription(stackName) //
            .withChangeSetName(changeSetName) //
            .withChangeSetType(changeSetType) //
            .withParameters(parameters).withTemplateBody(templateBody);
    final CreateChangeSetResult result = cloudFormation.createChangeSet(changeSetRequest);
    LOG.info("Change set created: {}", result);
    return result.getId();
}
项目:aws-sam-gradle    文件:TemplateService.java   
public String replaceParameters(String original, Collection<Parameter> parameters) {
    String result = original;
    for (final Parameter param : parameters) {
        LOG.debug("Replace '{}' with '{}'", param.getParameterKey(), param.getParameterValue());
        result = result.replace("${" + param.getParameterKey() + "}", param.getParameterValue());
    }
    return result;
}
项目:cerberus-lifecycle-cli    文件:CloudFormationService.java   
/**
 * Returns the current status of the named stack.
 *
 * @param stackId Stack name.
 * @return Stack outputs data.
 */
public Map<String, String> getStackParameters(final String stackId) {
    final DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackId);
    final DescribeStacksResult result = cloudFormationClient.describeStacks(request);
    final Map<String, String> parameters = Maps.newHashMap();

    if (result.getStacks().size() > 0) {
        parameters.putAll(result.getStacks().get(0).getParameters().stream().collect(
                Collectors.toMap(Parameter::getParameterKey, Parameter::getParameterValue)));

    }

    return parameters;
}
项目:cerberus-lifecycle-cli    文件:CloudFormationService.java   
/**
 * Converts a Map into a list of {@link com.amazonaws.services.cloudformation.model.Parameter} objects.
 *
 * @param parameterMap Map to be converted.
 * @return Collection of parameters.
 */
public Collection<Parameter> convertParameters(final Map<String, String> parameterMap) {
    final List<Parameter> parameterList = Lists.newArrayListWithCapacity(parameterMap.size());

    for (Map.Entry<String, String> entry : parameterMap.entrySet()) {
        final Parameter param = new Parameter()
                .withParameterKey(entry.getKey())
                .withParameterValue(entry.getValue());
        parameterList.add(param);
    }

    return parameterList;
}
项目:aws-maven-plugin    文件:CloudFormationDeployer.java   
private List<Parameter> buildParameters(Map<String, String> parameters) {
    final List<Parameter> params;
    if (parameters != null) {
        params = parameters //
                .entrySet() //
                .stream() //
                .map(p -> new Parameter().withParameterKey(p.getKey()).withParameterValue(p.getValue())) //
                .collect(Collectors.toList());
    } else {
        params = Collections.emptyList();
    }
    return params;
}
项目:lambadaframework    文件:Deployment.java   
public Collection<Parameter> getCloudFormationParameters() {
    Collection<Parameter> parameters = new ArrayList<>();
    for (Map.Entry<Object, Object> e : properties.entrySet()) {
        parameters.add(new Parameter().withParameterKey((String) e.getKey()).withParameterValue((String) e.getValue()));
    }
    return parameters;
}
项目:aws-cf-templates    文件:TestEC2AutoRecovery.java   
@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "ec2-auto-recovery-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    try {
        final KeyPair key = this.createKey(keyName);
        try {
            this.createStack(vpcStackName,
                    "vpc/vpc-2azs.yaml",
                    new Parameter().withParameterKey("ClassB").withParameterValue(classB)
            );
            try {
                this.createStack(stackName,
                        "ec2/ec2-auto-recovery.yaml",
                        new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName),
                        new Parameter().withParameterKey("KeyName").withParameterValue(keyName)
                );
                final String host = this.getStackOutputValue(stackName, "IPAddress");
                this.probeSSH(host, key);
            } finally {
                this.deleteStack(stackName);
            }
        } finally {
            this.deleteStack(vpcStackName);
        }
    } finally {
        this.deleteKey(keyName);
    }
}
项目:aws-cf-templates    文件:TestStaticWebsite.java   
@Test
public void test() {
    final String stackName = "static-website-" + this.random8String();
    final String domainName = this.generateDomain(stackName);
    final String redirectDomainName = this.generateDomain("www-" + stackName);
    try {
        this.createStack(stackName,
                "static-website/static-website.yaml",
                new Parameter().withParameterKey("DomainName").withParameterValue(domainName),
                new Parameter().withParameterKey("RedirectDomainName").withParameterValue(redirectDomainName),
                new Parameter().withParameterKey("CertificateType").withParameterValue("AcmCertificateArn"),
                new Parameter().withParameterKey("ExistingCertificate").withParameterValue(Config.get(Config.Key.CLOUDFRONT_ACM_CERTIFICATE_ARN)),
                new Parameter().withParameterKey("HostedZoneId").withParameterValue(Config.get(Config.Key.HOSTED_ZONE_ID))
        );
        final String url = "https://" + domainName;
        final Callable<HttpResponse> callable = () -> {
            final HttpResponse response = WS.url(url).timeout(10000).get();
            // check HTTP response code
            if (WS.getStatus(response) != 404) {
                throw new RuntimeException("404 expected, but saw " + WS.getStatus(response));
            }
            return response;
        };
        this.retry(callable);
    } finally {
        this.deleteStackAndRetryOnFailure(stackName);
    }
}
项目:aws-cf-templates    文件:TestVPCSshBastion.java   
@Test
public void test() {
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String bastionStackName = "vpc-ssh-bastion-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    try {
        final KeyPair key = this.createKey(keyName);
        try {
            this.createStack(vpcStackName,
                    "vpc/vpc-2azs.yaml",
                    new Parameter().withParameterKey("ClassB").withParameterValue(classB)
            );
            try {
                this.createStack(bastionStackName,
                        "vpc/vpc-ssh-bastion.yaml",
                        new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName),
                        new Parameter().withParameterKey("KeyName").withParameterValue(keyName)
                );
                final String host = this.getStackOutputValue(bastionStackName, "IPAddress");
                this.probeSSH(host, key);
            } finally {
                this.deleteStack(bastionStackName);
            }
        } finally {
            this.deleteStack(vpcStackName);
        }
    } finally {
        this.deleteKey(keyName);
    }
}