class Hygroscope::Template
Attributes
path[R]
Public Class Methods
new(path, region, profile)
click to toggle source
# File lib/hygroscope/template.rb, line 11 def initialize(path, region, profile) @path = path @region = region @profile = profile end
Public Instance Methods
compress()
click to toggle source
# File lib/hygroscope/template.rb, line 37 def compress JSON.parse(process).to_json end
parameters()
click to toggle source
# File lib/hygroscope/template.rb, line 41 def parameters template = JSON.parse(process) template['Parameters'] || [] end
process()
click to toggle source
Process a set of files with cfoo and return JSON
# File lib/hygroscope/template.rb, line 18 def process return @template if @template out = StringIO.new err = StringIO.new files = Dir.glob(File.join(@path, '*.{yml,yaml}')) cfoo = Cfoo::Factory.new(out, err).cfoo Dir.chdir('/') do cfoo.process(*files) end raise(TemplateYamlParseError, err.string) unless err.string.empty? @template = out.string @template end
process_to_file()
click to toggle source
Process a set of files with cfoo and write JSON to a temporary file
# File lib/hygroscope/template.rb, line 47 def process_to_file file = Tempfile.new(['hygroscope-', '.json']) file.write(process) file.close at_exit { file.unlink } file end
validate()
click to toggle source
# File lib/hygroscope/template.rb, line 57 def validate # Parsing the template to JSON and then re-outputting it is a form of # compression (removing all extra spaces) to keep within the 50KB limit # for CloudFormation templates. template = compress begin stack = Hygroscope::Stack.new('template-validator', @region, @profile) stack.client.validate_template(template_body: template) rescue => e raise e end end