Class: Hygroscope::Template
- Inherits:
-
Object
- Object
- Hygroscope::Template
- Defined in:
- lib/hygroscope/template.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #compress ⇒ Object
-
#initialize(path, region, profile) ⇒ Template
constructor
A new instance of Template.
- #parameters ⇒ Object
-
#process ⇒ Object
Process a set of files with cfoo and return JSON.
-
#process_to_file ⇒ Object
Process a set of files with cfoo and write JSON to a temporary file.
- #validate ⇒ Object
Constructor Details
#initialize(path, region, profile) ⇒ Template
Returns a new instance of Template.
11 12 13 14 15 |
# File 'lib/hygroscope/template.rb', line 11 def initialize(path, region, profile) @path = path @region = region @profile = profile end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/hygroscope/template.rb', line 9 def path @path end |
Instance Method Details
#compress ⇒ Object
37 38 39 |
# File 'lib/hygroscope/template.rb', line 37 def compress JSON.parse(process).to_json end |
#parameters ⇒ Object
41 42 43 44 |
# File 'lib/hygroscope/template.rb', line 41 def parameters template = JSON.parse(process) template['Parameters'] || [] end |
#process ⇒ Object
Process a set of files with cfoo and return JSON
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 ⇒ Object
Process a set of files with cfoo and write JSON to a temporary file
47 48 49 50 51 52 53 54 55 |
# 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 ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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 |