Ejemplo n.º 1
0
        public static ICloudFormationRequestBuilder Create(ITemplateResolver templateResolver,
                                                           string templateFile,
                                                           string templateParameterFile,
                                                           bool filesInPackage,
                                                           ICalamariFileSystem fileSystem,
                                                           IVariables variables,
                                                           string stackName,
                                                           List <string> capabilities,
                                                           bool disableRollback,
                                                           string roleArn,
                                                           IEnumerable <KeyValuePair <string, string> > tags,
                                                           StackArn stack,
                                                           Func <IAmazonCloudFormation> clientFactory)
        {
            var resolvedTemplate   = templateResolver.Resolve(templateFile, filesInPackage, variables);
            var resolvedParameters = templateResolver.MaybeResolve(templateParameterFile, filesInPackage, variables);

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

            return(new CloudFormationTemplate(() => variables.Evaluate(fileSystem.ReadFile(resolvedTemplate.Value)),
                                              CloudFormationParametersFile.Create(resolvedParameters, fileSystem, variables),
                                              stackName,
                                              capabilities,
                                              disableRollback,
                                              roleArn,
                                              tags,
                                              stack,
                                              clientFactory,
                                              variables));
        }
        public static ICloudFormationRequestBuilder Create(string templateS3Url,
                                                           string templateParameterS3Url,
                                                           ICalamariFileSystem fileSystem,
                                                           IVariables variables,
                                                           ILog log,
                                                           string stackName,
                                                           List <string> capabilities,
                                                           bool disableRollback,
                                                           string roleArn,
                                                           IEnumerable <KeyValuePair <string, string> > tags,
                                                           StackArn stack,
                                                           Func <IAmazonCloudFormation> clientFactory)
        {
            if (!string.IsNullOrWhiteSpace(templateParameterS3Url) && !templateParameterS3Url.StartsWith("http"))
            {
                throw new CommandException("Parameters file must start with http: " + templateParameterS3Url);
            }

            if (!string.IsNullOrWhiteSpace(templateS3Url) && !templateS3Url.StartsWith("http"))
            {
                throw new CommandException("Template file must start with http: " + templateS3Url);
            }

            var templatePath = string.IsNullOrWhiteSpace(templateParameterS3Url)
                ? Maybe <ResolvedTemplatePath> .None
                : new ResolvedTemplatePath(ParametersFile).AsSome();

            if (templatePath.Some())
            {
                DownloadS3(variables, log, templateParameterS3Url);
            }

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

            return(new CloudFormationS3Template(parameters,
                                                templateS3Url,
                                                stackName,
                                                capabilities,
                                                disableRollback,
                                                roleArn,
                                                tags,
                                                stack,
                                                clientFactory,
                                                variables));
        }