Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
aws-sdk-s3 instead of aws-sdk (#2481)
Browse files Browse the repository at this point in the history
* Added support for aws-sdk-s3 gem which is now preferred way to interact with s3.

Reference: https://github.com/aws/aws-sdk-ruby/blob/master/V3_UPGRADING_GUIDE.md#library-maintainer

* Drop support for aws-sdk gem
  • Loading branch information
morgoth authored and sidraval committed Mar 9, 2018
1 parent de92a5a commit 572bba0
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 32 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ Storage
Paperclip ships with 3 storage adapters:

* File Storage
* S3 Storage (via `aws-sdk`)
* S3 Storage (via `aws-sdk-s3`)
* Fog Storage

If you would like to use Paperclip with another storage, you can install these
Expand All @@ -593,10 +593,10 @@ _**NOTE**: This is a change from previous versions of Paperclip, but is overall
safer choice for the default file store._

You may also choose to store your files using Amazon's S3 service. To do so, include
the `aws-sdk` gem in your Gemfile:
the `aws-sdk-s3` gem in your Gemfile:

```ruby
gem 'aws-sdk', '~> 2.3.0'
gem 'aws-sdk-s3'
```

And then you can specify using S3 from `has_attached_file`.
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/rails_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
gem "jruby-openssl", :platform => :jruby
gem "capybara"
gem "gherkin"
gem "aws-sdk", "~> 2.0.0"
gem "aws-sdk-s3"
gem "racc", :platform => :rbx
gem "rubysl", :platform => :rbx
"""
Expand Down
21 changes: 6 additions & 15 deletions lib/paperclip/storage/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module Storage
# Amazon's S3 file hosting service is a scalable, easy place to store files for
# distribution. You can find out more about it at http://aws.amazon.com/s3
#
# To use Paperclip with S3, include the +aws-sdk+ gem in your Gemfile:
# gem 'aws-sdk'
# To use Paperclip with S3, include the +aws-sdk-s3+ gem in your Gemfile:
# gem 'aws-sdk-s3'
# There are a few S3-specific options for has_attached_file:
# * +s3_credentials+: Takes a path, a File, a Hash or a Proc. The path (or File) must point
# to a YAML file containing the +access_key_id+ and +secret_access_key+ that Amazon
Expand Down Expand Up @@ -96,7 +96,7 @@ module Storage
# separate parts of your file name.
# * +s3_host_name+: If you are using your bucket in Tokyo region
# etc, write host_name (e.g., 's3-ap-northeast-1.amazonaws.com').
# * +s3_region+: For aws-sdk v2, s3_region is required.
# * +s3_region+: For aws-sdk-s3, s3_region is required.
# * +s3_metadata+: These key/value pairs will be stored with the
# object. This option works by prefixing each key with
# "x-amz-meta-" before sending it as a header on the object
Expand All @@ -118,20 +118,16 @@ module Storage
# :s3_storage_class => :REDUCED_REDUNDANCY
#
# Other storage classes, such as <tt>:STANDARD_IA</tt>, are also available—see the
# documentation for the <tt>aws-sdk</tt> gem for the full list.
# documentation for the <tt>aws-sdk-s3</tt> gem for the full list.

module S3
def self.extended base
begin
require 'aws-sdk'
require "aws-sdk-s3"
rescue LoadError => e
e.message << " (You may need to install the aws-sdk gem)"
e.message << " (You may need to install the aws-sdk-s3 gem)"
raise e
end
if Gem::Version.new(Aws::VERSION) >= Gem::Version.new(2) &&
Gem::Version.new(Aws::VERSION) <= Gem::Version.new("2.0.33")
raise LoadError, "paperclip does not support aws-sdk versions 2.0.0 - 2.0.33. Please upgrade aws-sdk to a newer version."
end

base.instance_eval do
@s3_options = @options[:s3_options] || {}
Expand Down Expand Up @@ -159,11 +155,6 @@ def self.extended base

@http_proxy = @options[:http_proxy] || nil

if @options.has_key?(:use_accelerate_endpoint) &&
Gem::Version.new(Aws::VERSION) < Gem::Version.new("2.3.0")
raise LoadError, ":use_accelerate_endpoint is only available from aws-sdk version 2.3.0. Please upgrade aws-sdk to a newer version."
end

@use_accelerate_endpoint = @options[:use_accelerate_endpoint]
end

Expand Down
2 changes: 1 addition & 1 deletion paperclip.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('rspec', '~> 3.0')
s.add_development_dependency('appraisal')
s.add_development_dependency('mocha')
s.add_development_dependency('aws-sdk', '>= 2.3.0', '< 3.0')
s.add_development_dependency('aws-sdk-s3')
s.add_development_dependency('bourne')
s.add_development_dependency('cucumber-rails')
s.add_development_dependency('cucumber-expressions', '4.0.3') # TODO: investigate failures on 4.0.4
Expand Down
12 changes: 6 additions & 6 deletions spec/paperclip/storage/s3_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'aws-sdk'
require "spec_helper"
require "aws-sdk-s3"

describe Paperclip::Storage::S3 do
before do
Expand Down Expand Up @@ -237,7 +237,7 @@ def aws2_add_region
end
end

# if using aws-sdk-v2, the s3_host_name will be defined by the s3_region
# the s3_host_name will be defined by the s3_region
context "s3_host_name" do
before do
rebuild_model storage: :s3,
Expand Down Expand Up @@ -282,7 +282,7 @@ class << @dummy
end
end

context "use_accelerate_endpoint", if: aws_accelerate_available? do
context "use_accelerate_endpoint" do
context "defaults to false" do
before do
rebuild_model(
Expand All @@ -308,7 +308,7 @@ class << @dummy
end
end

context "set to true", if: aws_accelerate_available? do
context "set to true" do
before do
rebuild_model(
storage: :s3,
Expand Down Expand Up @@ -793,7 +793,7 @@ def counter
end
end

# for aws-sdk-v2 the bucket.name is determined by the :s3_region
# the bucket.name is determined by the :s3_region
context "Parsing S3 credentials with a s3_host_name in them" do
before do
rebuild_model storage: :s3,
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
config.include TestData
config.include Reporting
config.extend VersionHelper
config.extend ConditionalFilterHelper
config.mock_framework = :mocha
config.before(:all) do
rebuild_model
Expand Down
5 changes: 0 additions & 5 deletions spec/support/conditional_filter_helper.rb

This file was deleted.

0 comments on commit 572bba0

Please sign in to comment.