Sha256: 403f2e75e3ab0ea6453860cc0ffd6b2351de7cd4339c9c0726a93006e5f6f36d

Contents?: true

Size: 1.6 KB

Versions: 42

Compression:

Stored size: 1.6 KB

Contents

require 'json'

module DPL
  class Provider
    class S3 < Provider
      requires 'aws-sdk'
      requires 'mime-types'

      def api
        @api ||= AWS::S3.new(endpoint: options[:endpoint] || 's3.amazonaws.com')
      end

      def needs_key?
        false
      end

      def check_app

      end

      def setup_auth
        AWS.config(:access_key_id => option(:access_key_id), :secret_access_key => option(:secret_access_key), :region => options[:region]||'us-east-1')
      end

      def check_auth
        setup_auth
        log "Logging in with Access Key: #{option(:access_key_id)[-4..-1].rjust(20, '*')}"
      end

      def upload_path(filename)
        [options[:upload_dir], filename].compact.join("/")
      end

      def push_app
        Dir.chdir(options.fetch(:local_dir, Dir.pwd)) do
          Dir.glob("**/*") do |filename|
            content_type = MIME::Types.type_for(filename).first.to_s
            api.buckets[option(:bucket)].objects.create(upload_path(filename), File.read(filename), :content_type => content_type) unless File.directory?(filename)
          end
        end
      end

      def deploy
        super
      rescue AWS::S3::Errors::InvalidAccessKeyId
        raise Error, "Invalid S3 Access Key Id, Stopping Deploy"
      rescue AWS::S3::Errors::SignatureDoesNotMatch
        raise Error, "Aws Secret Key does not match Access Key Id, Stopping Deploy"
      rescue AWS::S3::Errors::AccessDenied
        raise Error, "Oops, It looks like you tried to write to a bucket that isn't yours or doesn't exist yet. Please create the bucket before trying to write to it."
      end

    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
dpl-1.5.11.travis.414.1 lib/dpl/provider/s3.rb
dpl-1.5.10 lib/dpl/provider/s3.rb
dpl-1.5.10.travis.413.1 lib/dpl/provider/s3.rb
dpl-1.5.10.travis.402.1 lib/dpl/provider/s3.rb
dpl-1.6.0.travis.399.1 lib/dpl/provider/s3.rb
dpl-1.5.9 lib/dpl/provider/s3.rb
dpl-1.5.9.travis.397.1 lib/dpl/provider/s3.rb
dpl-1.5.9.travis.394.1 lib/dpl/provider/s3.rb
dpl-1.5.9.travis.393.1 lib/dpl/provider/s3.rb
dpl-1.5.9.travis.390.1 lib/dpl/provider/s3.rb
dpl-1.5.9.travis.373.1 lib/dpl/provider/s3.rb
dpl-1.5.9.travis.372.1 lib/dpl/provider/s3.rb
dpl-1.5.8 lib/dpl/provider/s3.rb
dpl-1.5.9.travis.368.1 lib/dpl/provider/s3.rb
dpl-1.5.8.travis.367.1 lib/dpl/provider/s3.rb
dpl-1.5.8.travis.365.1 lib/dpl/provider/s3.rb
dpl-1.5.8.travis.364.1 lib/dpl/provider/s3.rb
dpl-1.5.8.travis.359.1 lib/dpl/provider/s3.rb
dpl-1.5.8.travis.356.1 lib/dpl/provider/s3.rb
dpl-1.5.8.travis.336.1 lib/dpl/provider/s3.rb