Sha256: 1f014b65c89fbbcaae1bf251752753e68c1cbd2c222b3f4ca568ffd10fea85b1

Contents?: true

Size: 731 Bytes

Versions: 3

Compression:

Stored size: 731 Bytes

Contents

require 'fog'

class Chef
  class Knife
    class S3Source
      attr_accessor :url

      def self.fetch(url)
        source = Chef::Knife::S3Source.new
        source.url = url
        source.body
      end

      def body
        bucket_obj.files.get(path).body
      end

      private

      def bucket_obj
        @bucket_obj ||= fog.directories.get(bucket)
      end

      def bucket
        URI(@url).host
      end

      def path
        URI(@url).path.sub(/^\//, '')
      end

      def fog
        @fog ||= Fog::Storage::AWS.new(
          aws_access_key_id: Chef::Config[:knife][:aws_access_key_id],
          aws_secret_access_key: Chef::Config[:knife][:aws_secret_access_key]
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
knife-ec2-0.10.0 lib/chef/knife/s3_source.rb
knife-ec2-0.10.0.rc.2 lib/chef/knife/s3_source.rb
knife-ec2-0.10.0.rc.1 lib/chef/knife/s3_source.rb