Ejemplo n.º 1
0
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            var filesInPackage   = !string.IsNullOrWhiteSpace(pathToPackage);
            var environment      = AwsEnvironmentGeneration.Create(log, variables).GetAwaiter().GetResult();
            var templateResolver = new TemplateResolver(fileSystem);

            IAmazonCloudFormation ClientFactory() => ClientHelpers.CreateCloudFormationClient(environment);
            StackArn StackProvider(RunningDeployment x) => new StackArn(stackName);
            ChangeSetArn ChangesetProvider(RunningDeployment x) => new ChangeSetArn(x.Variables[AwsSpecialVariables.CloudFormation.Changesets.Arn]);
            string RoleArnProvider(RunningDeployment x) => x.Variables[AwsSpecialVariables.CloudFormation.RoleArn];

            var iamCapabilities = JsonConvert.DeserializeObject <List <string> >(variables.Get(AwsSpecialVariables.IamCapabilities, "[]"));

            CloudFormationTemplate TemplateFactory()
            {
                var resolvedTemplate   = templateResolver.Resolve(templateFile, filesInPackage, variables);
                var resolvedParameters = templateResolver.MaybeResolve(templateParameterFile, filesInPackage, variables);

                if (templateParameterFile != null && !resolvedParameters.Some())
                {
                    throw new CommandException("Could not find template parameters file: " + templateParameterFile);
                }

                var parameters = CloudFormationParametersFile.Create(resolvedParameters, fileSystem, variables);

                return(CloudFormationTemplate.Create(resolvedTemplate, parameters, fileSystem, variables));
            }

            var stackEventLogger = new StackEventLogger(log);

            var conventions = new List <IConvention>
            {
                new LogAwsUserInfoConvention(environment),
                new DelegateInstallConvention(d => extractPackage.ExtractToStagingDirectory(pathToPackage)),

                //Create or Update the stack using changesets
                new AggregateInstallationConvention(
                    new GenerateCloudFormationChangesetNameConvention(log),
                    new CreateCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, RoleArnProvider, TemplateFactory, iamCapabilities),
                    new DescribeCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, ChangesetProvider),
                    new ExecuteCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, ChangesetProvider, waitForComplete)
                    .When(ImmediateChangesetExecution),
                    new CloudFormationOutputsAsVariablesConvention(ClientFactory, stackEventLogger, StackProvider, () => TemplateFactory().HasOutputs)
                    .When(ImmediateChangesetExecution)
                    ).When(ChangesetsEnabled),

                //Create or update stack using a template (no changesets)
                new AggregateInstallationConvention(
                    new  DeployAwsCloudFormationConvention(
                        ClientFactory,
                        TemplateFactory,
                        stackEventLogger,
                        StackProvider,
                        RoleArnProvider,
                        waitForComplete,
                        stackName,
                        iamCapabilities,
                        disableRollback,
                        environment),
                    new CloudFormationOutputsAsVariablesConvention(ClientFactory, stackEventLogger, StackProvider, () => TemplateFactory().HasOutputs)
                    )
                .When(ChangesetsDisabled)
            };

            var deployment       = new RunningDeployment(pathToPackage, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions);

            conventionRunner.RunConventions();
            return(0);
        }
 public CreateS3BucketConvention(AwsEnvironmentGeneration awsEnvironmentGeneration, Func <RunningDeployment, string> bucketFactory)
 {
     this.awsEnvironmentGeneration = awsEnvironmentGeneration;
     this.bucketFactory            = bucketFactory;
 }
Ejemplo n.º 3
0
 public static IAmazonCloudFormation CreateCloudFormationClient(AwsEnvironmentGeneration environment)
 {
     return(new AmazonCloudFormationClient(environment.AwsCredentials,
                                           environment.AsClientConfig <AmazonCloudFormationConfig>()));
 }
Ejemplo n.º 4
0
 public LogAwsUserInfoConvention(AwsEnvironmentGeneration awsEnvironmentGeneration)
 {
     this.awsEnvironmentGeneration = awsEnvironmentGeneration;
 }
Ejemplo n.º 5
0
 public static AmazonS3Client CreateS3Client(AwsEnvironmentGeneration environment)
 {
     return(new AmazonS3Client(environment.AwsCredentials, environment.AsClientConfig <AmazonS3Config>()));
 }
Ejemplo n.º 6
0
 public static AmazonSecurityTokenServiceClient CreateSecurityTokenServiceClient(
     AwsEnvironmentGeneration environment)
 {
     return(new AmazonSecurityTokenServiceClient(environment.AwsCredentials, environment.AsClientConfig <AmazonSecurityTokenServiceConfig>()));
 }
Ejemplo n.º 7
0
 public static AmazonIdentityManagementServiceClient CreateIdentityManagementServiceClient(
     AwsEnvironmentGeneration environment)
 {
     return(new AmazonIdentityManagementServiceClient(environment.AwsCredentials, environment.AsClientConfig <AmazonIdentityManagementServiceConfig>()));
 }
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);
            if (variablesFile != null && !File.Exists(variablesFile))
            {
                throw new CommandException("Could not find variables file: " + variablesFile);
            }

            var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile,
                                                           sensitiveVariablesPassword);

            var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            var filesInPackage   = !string.IsNullOrWhiteSpace(packageFile);
            var environment      = new AwsEnvironmentGeneration(variables);
            var templateResolver = new TemplateResolver(fileSystem);

            IAmazonCloudFormation ClientFactory() => ClientHelpers.CreateCloudFormationClient(environment);
            StackArn StackProvider(RunningDeployment x) => new StackArn(stackName);
            ChangeSetArn ChangesetProvider(RunningDeployment x) => new ChangeSetArn(x.Variables[AwsSpecialVariables.CloudFormation.Changesets.Arn]);
            string RoleArnProvider(RunningDeployment x) => x.Variables[AwsSpecialVariables.CloudFormation.RoleArn];

            CloudFormationTemplate TemplateFactory()
            {
                var resolvedTemplate   = templateResolver.Resolve(templateFile, filesInPackage, variables);
                var resolvedParameters = templateResolver.MaybeResolve(templateParameterFile, filesInPackage, variables);

                if (templateParameterFile != null && !resolvedParameters.Some())
                {
                    throw new CommandException("Could not find template parameters file: " + templateParameterFile);
                }

                var parameters = CloudFormationParametersFile.Create(resolvedParameters, fileSystem, variables);

                return(CloudFormationTemplate.Create(resolvedTemplate, parameters, fileSystem, variables));
            }

            var stackEventLogger = new StackEventLogger(new LogWrapper());

            var conventions = new List <IConvention>
            {
                new LogAwsUserInfoConvention(environment),
                new ContributeEnvironmentVariablesConvention(),
                new LogVariablesConvention(),
                new ExtractPackageToStagingDirectoryConvention(new GenericPackageExtractorFactory().createStandardGenericPackageExtractor(), fileSystem),

                //Create or Update the stack using changesets
                new AggregateInstallationConvention(
                    new GenerateCloudFormationChangesetNameConvention(),
                    new CreateCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, RoleArnProvider, TemplateFactory, iamCapabilities),
                    new DescribeCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, ChangesetProvider),
                    new ExecuteCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, ChangesetProvider, waitForComplete)
                    .When(ImmediateChangesetExecution),
                    new CloudFormationOutputsAsVariablesConvention(ClientFactory, stackEventLogger, StackProvider, () => TemplateFactory().HasOutputs)
                    .When(ImmediateChangesetExecution)
                    ).When(ChangesetsEnabled),

                //Create or update stack using a template (no changesets)
                new AggregateInstallationConvention(
                    new  DeployAwsCloudFormationConvention(
                        ClientFactory,
                        TemplateFactory,
                        stackEventLogger,
                        StackProvider,
                        RoleArnProvider,
                        waitForComplete,
                        stackName,
                        iamCapabilities,
                        disableRollback,
                        environment),
                    new CloudFormationOutputsAsVariablesConvention(ClientFactory, stackEventLogger, StackProvider, () => TemplateFactory().HasOutputs)
                    )
                .When(ChangesetsDisabled)
            };

            var deployment       = new RunningDeployment(packageFile, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions);

            conventionRunner.RunConventions();
            return(0);
        }
Ejemplo n.º 9
0
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            var filesInPackage   = !string.IsNullOrWhiteSpace(pathToPackage);
            var environment      = AwsEnvironmentGeneration.Create(log, variables).GetAwaiter().GetResult();
            var templateResolver = new TemplateResolver(fileSystem);

            IAmazonCloudFormation ClientFactory() => ClientHelpers.CreateCloudFormationClient(environment);
            StackArn StackProvider(RunningDeployment x) => new StackArn(stackName);
            ChangeSetArn ChangesetProvider(RunningDeployment x) => new ChangeSetArn(x.Variables[AwsSpecialVariables.CloudFormation.Changesets.Arn]);
            string RoleArnProvider(RunningDeployment x) => x.Variables[AwsSpecialVariables.CloudFormation.RoleArn];

            var iamCapabilities = JsonConvert.DeserializeObject <List <string> >(variables.Get(AwsSpecialVariables.IamCapabilities, "[]"));
            var tags            = JsonConvert.DeserializeObject <List <KeyValuePair <string, string> > >(variables.Get(AwsSpecialVariables.CloudFormation.Tags, "[]"));
            var deployment      = new RunningDeployment(pathToPackage, variables);

            ICloudFormationRequestBuilder TemplateFactory() => string.IsNullOrWhiteSpace(templateS3Url)
                ? CloudFormationTemplate.Create(templateResolver,
                                                templateFile,
                                                templateParameterFile,
                                                filesInPackage,
                                                fileSystem,
                                                variables,
                                                stackName,
                                                iamCapabilities,
                                                disableRollback,
                                                RoleArnProvider(deployment),
                                                tags,
                                                StackProvider(deployment),
                                                ClientFactory)
                : CloudFormationS3Template.Create(templateS3Url,
                                                  templateParameterS3Url,
                                                  fileSystem,
                                                  variables,
                                                  log,
                                                  stackName,
                                                  iamCapabilities,
                                                  disableRollback,
                                                  RoleArnProvider(deployment),
                                                  tags,
                                                  StackProvider(deployment),
                                                  ClientFactory);

            var stackEventLogger = new StackEventLogger(log);

            var conventions = new List <IConvention>
            {
                new LogAwsUserInfoConvention(environment),
                new DelegateInstallConvention(d => extractPackage.ExtractToStagingDirectory(pathToPackage)),
                new StructuredConfigurationVariablesConvention(new StructuredConfigurationVariablesBehaviour(structuredConfigVariablesService)),

                //Create or Update the stack using changesets
                new AggregateInstallationConvention(
                    new GenerateCloudFormationChangesetNameConvention(log),
                    new CreateCloudFormationChangeSetConvention(ClientFactory,
                                                                stackEventLogger,
                                                                StackProvider,
                                                                TemplateFactory),
                    new DescribeCloudFormationChangeSetConvention(ClientFactory, stackEventLogger, StackProvider, ChangesetProvider),
                    new ExecuteCloudFormationChangeSetConvention(ClientFactory,
                                                                 stackEventLogger,
                                                                 StackProvider,
                                                                 ChangesetProvider,
                                                                 waitForComplete)
                    .When(ImmediateChangesetExecution),
                    new CloudFormationOutputsAsVariablesConvention(ClientFactory, stackEventLogger, StackProvider)
                    .When(ImmediateChangesetExecution)
                    ).When(ChangesetsEnabled),

                //Create or update stack using a template (no changesets)
                new AggregateInstallationConvention(
                    new DeployAwsCloudFormationConvention(
                        ClientFactory,
                        TemplateFactory,
                        stackEventLogger,
                        StackProvider,
                        RoleArnProvider,
                        waitForComplete,
                        stackName,
                        environment),
                    new CloudFormationOutputsAsVariablesConvention(ClientFactory, stackEventLogger, StackProvider)
                    )
                .When(ChangesetsDisabled)
            };

            var conventionRunner = new ConventionProcessor(deployment, conventions, log);

            conventionRunner.RunConventions();
            return(0);
        }