Skip to content

Commit

Permalink
First pass at making specs run with Aws-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
davetchen authored and Jon Yurek committed Aug 20, 2015
1 parent 9ef9b51 commit ccaaaad
Show file tree
Hide file tree
Showing 2 changed files with 358 additions and 171 deletions.
20 changes: 14 additions & 6 deletions lib/paperclip/storage/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ def self.extended base
begin
require 'aws-sdk'
const_set('AWS_CLASS', defined?(::Aws) ? ::Aws : ::AWS)
const_set('DEFAULT_PERMISSION', defined?(::AWS) ? :public_read : :'public-read')
const_set('AWS_BASE_ERROR',
defined?(::Aws) ? Aws::Errors::ServiceError : AWS::Errors::Base)
const_set('DEFAULT_PERMISSION',
defined?(::AWS) ? :public_read : :'public-read')

rescue LoadError => e
e.message << " (You may need to install the aws-sdk gem)"
raise e
Expand Down Expand Up @@ -253,7 +257,7 @@ def s3_interface
config[:proxy_uri] = URI::HTTP.build(proxy_opts)
end

[:access_key_id, :secret_access_key, :credential_provider].each do |opt|
[:access_key_id, :secret_access_key, :credential_provider, :credentials].each do |opt|
config[opt] = s3_credentials[opt] if s3_credentials[opt]
end

Expand Down Expand Up @@ -332,7 +336,7 @@ def exists?(style = default_style)
else
false
end
rescue AWS_CLASS::Errors::Base => e
rescue AWS_BASE_ERROR => e
false
end

Expand All @@ -358,7 +362,11 @@ def s3_protocol(style = default_style, with_colon = false)
end

def create_bucket
s3_interface.buckets.create(bucket_name)
if aws_v1?
s3_interface.buckets.create(bucket_name)
else
s3_interface.bucket(bucket_name).create
end
end

def flush_writes #:nodoc:
Expand Down Expand Up @@ -426,7 +434,7 @@ def flush_deletes #:nodoc:
else
s3_bucket.object(path.sub(%r{\A/},''))
end.delete
rescue AWS_CLASS::Errors::Base => e
rescue AWS_BASE_ERROR => e
# Ignore this.
end
end
Expand All @@ -440,7 +448,7 @@ def copy_to_local_file(style, local_dest_path)
local_file.write(chunk)
end
end
rescue AWS_CLASS::Errors::Base => e
rescue AWS_BASE_ERROR => e
warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
false
end
Expand Down
Loading

0 comments on commit ccaaaad

Please sign in to comment.