module StackMaster::TemplateUtils
Constants
- JSON_IDENTIFICATION_PATTERN
Matches if the first non-whitespace character is a '{', handling cases with leading whitespace and extra (whitespace-only) lines.
- MAX_S3_TEMPLATE_SIZE
- MAX_TEMPLATE_SIZE
Public Instance Methods
identify_template_format(template_body)
click to toggle source
# File lib/stack_master/template_utils.rb, line 11 def identify_template_format(template_body) if template_body =~ JSON_IDENTIFICATION_PATTERN :json else :yaml end end
maybe_compressed_template_body(template_body)
click to toggle source
# File lib/stack_master/template_utils.rb, line 30 def maybe_compressed_template_body(template_body) # Do not compress the template if it's not JSON because parsing YAML as a hash ignores # CloudFormation-specific tags such as !Ref return template_body if template_body.size <= MAX_TEMPLATE_SIZE || identify_template_format(template_body) != :json JSON.dump(template_hash(template_body)) end
template_hash(template_body=nil)
click to toggle source
# File lib/stack_master/template_utils.rb, line 19 def template_hash(template_body=nil) return unless template_body template_format = identify_template_format(template_body) case template_format when :json JSON.parse(template_body) when :yaml YAML.load(template_body) end end