class Lono::Cfn::Download

Public Instance Methods

convert_to_yaml(body) click to toggle source
# File lib/lono/cfn/download.rb, line 35
def convert_to_yaml(body)
  json?(body) ? YAML.dump(JSON.parse(body)) : body
end
download_path() click to toggle source
# File lib/lono/cfn/download.rb, line 43
def download_path
  "#{Lono.config.output_path}/#{@blueprint}/templates/#{@blueprint}.yml"
end
download_stack() click to toggle source
# File lib/lono/cfn/download.rb, line 22
def download_stack
  source = @options[:source]
  if source
    open(source).read # url or file
  else
    resp = cfn.get_template(
      stack_name: @stack,
      template_stage: "Original"
    )
    resp.template_body
  end
end
download_template() click to toggle source
# File lib/lono/cfn/download.rb, line 15
def download_template
  body = download_stack
  body = convert_to_yaml(body)
  FileUtils.mkdir_p(File.dirname(download_path))
  IO.write(download_path, body)
end
json?(body) click to toggle source
# File lib/lono/cfn/download.rb, line 39
def json?(body)
  !!JSON.parse(body) rescue false
end
name() click to toggle source
# File lib/lono/cfn/download.rb, line 47
def name
  @options[:name] || @stack
end
run() click to toggle source
# File lib/lono/cfn/download.rb, line 8
def run
  pretty_path = download_path.sub("#{Lono.root}/", '')
  puts "Downloading template to: #{pretty_path}"
  return if @options[:noop]
  download_template
end