Sha256: aaf710dd726866693817153e76ea9eb515c7c4b1eba8f4289c7781437b5487d0

Contents?: true

Size: 845 Bytes

Versions: 1

Compression:

Stored size: 845 Bytes

Contents

require 'aws-sdk'

module Itamae
  module Resource
    class S3File < File
      define_attribute :object_key, type: String, required: true
      define_attribute :region, type: String, required: true
      define_attribute :bucket, type: String, required: true
      define_attribute :profile, type: String, default: 'default'

      private

      def pre_action
        credentials = Aws::SharedCredentials.new(profile_name: attributes.profile)
        @s3 = Aws::S3::Client.new(region: attributes.region, credentials: credentials)
        attributes.content = fetch_content

        super
      end

      def fetch_content
        case @current_action
        when :create, :delete, :edit
          resp = @s3.get_object(bucket: attributes.bucket, key: attributes.object_key)
        end

        resp.body.read
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
itamae-spec-0.0.3 lib/itamae-spec/resource/s3_file.rb