Sha256: 40cf457cd01864d95056e42df8b917a9dfe388a4ff95efe036893fd9169bbefe

Contents?: true

Size: 691 Bytes

Versions: 28

Compression:

Stored size: 691 Bytes

Contents

require 'json'

class Lono::Cfn
  class Download < Base
    def run
      puts "Download existing template to: #{download_path}"
      return if @options[:noop]
      download_template
    end

    def download_template
      resp = cfn.get_template(
        stack_name: @stack_name,
        template_stage: "Original"
      )
      body = convert_to_yaml(resp.template_body)
      IO.write(download_path, body)
    end

    def convert_to_yaml(body)
      json?(body) ? YAML.dump(JSON.parse(body)) : body
    end

    def json?(body)
      !!JSON.parse(body) rescue false
    end

    def download_path
      name = @options[:name] || @stack_name
      "/tmp/#{name}.yml"
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
lono-6.1.11 lib/lono/cfn/download.rb
lono-6.1.10 lib/lono/cfn/download.rb
lono-6.1.9 lib/lono/cfn/download.rb
lono-6.1.8 lib/lono/cfn/download.rb
lono-6.1.7 lib/lono/cfn/download.rb
lono-6.1.6 lib/lono/cfn/download.rb
lono-6.1.5 lib/lono/cfn/download.rb
lono-6.1.4 lib/lono/cfn/download.rb
lono-6.1.3 lib/lono/cfn/download.rb
lono-6.1.2 lib/lono/cfn/download.rb
lono-6.1.1 lib/lono/cfn/download.rb
lono-6.1.0 lib/lono/cfn/download.rb
lono-6.0.1 lib/lono/cfn/download.rb
lono-6.0.0 lib/lono/cfn/download.rb
lono-5.3.4 lib/lono/cfn/download.rb
lono-5.3.3 lib/lono/cfn/download.rb
lono-5.3.2 lib/lono/cfn/download.rb
lono-5.3.1 lib/lono/cfn/download.rb
lono-5.3.0 lib/lono/cfn/download.rb
lono-5.2.8 lib/lono/cfn/download.rb