Sha256: 3dc2d5b615c979b0176d97a6afd544be57d3431ccd2917078fa8c36fef0563a9

Contents?: true

Size: 928 Bytes

Versions: 66

Compression:

Stored size: 928 Bytes

Contents

module Jets::Cfn
  class TemplateSource
    include Jets::AwsServices

    attr_reader :path

    def initialize(path, options)
      @path = path
      @options = options
    end

    def body
      @body ||= IO.read(path)
    end

    def url
      @url ||= upload_file_to_s3
    end

    def to_h
      if upload_to_s3?
        from_s3
      else
        from_path
      end
    end

    private

    def upload_to_s3?
      bucket_name.present?
    end

    def from_s3
      {
        template_url: url
      }
    end

    def from_path
      {
        template_body: body
      }
    end

    def upload_file_to_s3
      obj = s3_resource.bucket(bucket_name).object(s3_key)
      obj.upload_file(path)

      "https://s3.amazonaws.com/#{bucket_name}/#{s3_key}"
    end

    def bucket_name
      @options[:s3_bucket]
    end

    def s3_key
      @s3_key ||= "jets/cfn-templates/#{File.basename(path)}"
    end
  end
end

Version data entries

66 entries across 66 versions & 2 rubygems

Version Path
jets-4.0.12 lib/jets/cfn/template_source.rb
jets-4.0.11 lib/jets/cfn/template_source.rb
jets-4.0.10 lib/jets/cfn/template_source.rb
jets-4.0.9 lib/jets/cfn/template_source.rb
jets-4.0.8 lib/jets/cfn/template_source.rb
jets-4.0.7 lib/jets/cfn/template_source.rb
jets-4.0.6 lib/jets/cfn/template_source.rb
jets-4.0.5 lib/jets/cfn/template_source.rb
jets-4.0.4 lib/jets/cfn/template_source.rb
jets-4.0.3 lib/jets/cfn/template_source.rb
jets-4.0.2 lib/jets/cfn/template_source.rb
jets-4.0.1 lib/jets/cfn/template_source.rb
jets-4.0.0 lib/jets/cfn/template_source.rb
jets-3.2.2 lib/jets/cfn/template_source.rb
jets-3.2.1 lib/jets/cfn/template_source.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/cfn/template_source.rb
jets-3.2.0 lib/jets/cfn/template_source.rb
jets-3.1.5 lib/jets/cfn/template_source.rb
jets-3.1.4 lib/jets/cfn/template_source.rb
jets-3.1.3 lib/jets/cfn/template_source.rb