class CfnFlow::Template

Attributes

local_path[R]

Public Class Methods

new(local_path) click to toggle source
# File lib/cfn_flow/template.rb, line 8
def initialize(local_path)
  @local_path = local_path
end

Public Instance Methods

bucket() click to toggle source
# File lib/cfn_flow/template.rb, line 66
def bucket
  CfnFlow.template_s3_bucket
end
is_cfn_template?() click to toggle source

Determine if this file is a CFN template

# File lib/cfn_flow/template.rb, line 21
def is_cfn_template?
  local_data.is_a?(Hash) && local_data.key?('Resources')
end
json?() click to toggle source
# File lib/cfn_flow/template.rb, line 16
def json?
  ! yaml?
end
key(release) click to toggle source

S3 methods

# File lib/cfn_flow/template.rb, line 33
def key(release)
  # Replace leading './' in local_path
  clean_path = local_path.sub(/\A\.\//, '')
  File.join(*[s3_prefix, release, clean_path].compact)
end
local_data() click to toggle source
# File lib/cfn_flow/template.rb, line 51
def local_data
  data = ERB.new(File.read(local_path)).result(binding)
  # We *could* load JSON as YAML, but that would generate confusing errors
  # in the case of a JSON syntax error.
  @local_data ||= yaml? ? YAML.load(data) : MultiJson.load(data)
rescue Exception => error
  # Tag & re-raise any error
  error.extend(CfnFlow::Template::Error)
  raise error
end
s3_object(release) click to toggle source
# File lib/cfn_flow/template.rb, line 39
def s3_object(release)
  Aws::S3::Object.new(bucket, key(release))
end
s3_prefix() click to toggle source
# File lib/cfn_flow/template.rb, line 70
def s3_prefix
  CfnFlow.template_s3_prefix
end
to_json() click to toggle source
# File lib/cfn_flow/template.rb, line 62
def to_json
  @to_json ||= MultiJson.dump(local_data, pretty: true)
end
upload(release) click to toggle source
# File lib/cfn_flow/template.rb, line 47
def upload(release)
  s3_object(release).put(body: to_json)
end
url(release) click to toggle source
# File lib/cfn_flow/template.rb, line 43
def url(release)
  s3_object(release).public_url
end
validate!() click to toggle source

Returns a response object if valid, or raises an Aws::CloudFormation::Errors::ValidationError with an error message

# File lib/cfn_flow/template.rb, line 27
def validate!
  cfn.validate_template(template_body: to_json)
end
yaml?() click to toggle source
# File lib/cfn_flow/template.rb, line 12
def yaml?
  local_path.end_with?('.yml')
end

Private Instance Methods

cfn() click to toggle source
# File lib/cfn_flow/template.rb, line 75
def cfn
  CfnFlow.cfn_client
end