From 572bba0ec2a8b3b9f56d845a2cebecff34b5a11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Wn=C4=99trzak?= Date: Fri, 9 Mar 2018 17:34:37 +0100 Subject: [PATCH] aws-sdk-s3 instead of aws-sdk (#2481) * 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 --- README.md | 6 +++--- features/step_definitions/rails_steps.rb | 2 +- lib/paperclip/storage/s3.rb | 21 ++++++--------------- paperclip.gemspec | 2 +- spec/paperclip/storage/s3_spec.rb | 12 ++++++------ spec/spec_helper.rb | 1 - spec/support/conditional_filter_helper.rb | 5 ----- 7 files changed, 17 insertions(+), 32 deletions(-) delete mode 100644 spec/support/conditional_filter_helper.rb diff --git a/README.md b/README.md index 9d9eb75e9..cd31fc82a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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`. diff --git a/features/step_definitions/rails_steps.rb b/features/step_definitions/rails_steps.rb index bbe15b0a7..0193a7255 100644 --- a/features/step_definitions/rails_steps.rb +++ b/features/step_definitions/rails_steps.rb @@ -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 """ diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index d0044ec5a..b387edc21 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -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 @@ -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 @@ -118,20 +118,16 @@ module Storage # :s3_storage_class => :REDUCED_REDUNDANCY # # Other storage classes, such as :STANDARD_IA, are also available—see the - # documentation for the aws-sdk gem for the full list. + # documentation for the aws-sdk-s3 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] || {} @@ -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 diff --git a/paperclip.gemspec b/paperclip.gemspec index d2b941776..94d8e6685 100644 --- a/paperclip.gemspec +++ b/paperclip.gemspec @@ -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 diff --git a/spec/paperclip/storage/s3_spec.rb b/spec/paperclip/storage/s3_spec.rb index 99d31b1e4..f92c0e0af 100644 --- a/spec/paperclip/storage/s3_spec.rb +++ b/spec/paperclip/storage/s3_spec.rb @@ -1,5 +1,5 @@ -require 'spec_helper' -require 'aws-sdk' +require "spec_helper" +require "aws-sdk-s3" describe Paperclip::Storage::S3 do before do @@ -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, @@ -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( @@ -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, @@ -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, diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4dfe24b26..9cbbc44ea 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/support/conditional_filter_helper.rb b/spec/support/conditional_filter_helper.rb deleted file mode 100644 index 1277552e7..000000000 --- a/spec/support/conditional_filter_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -module ConditionalFilterHelper - def aws_accelerate_available? - (Gem::Version.new(Aws::VERSION) >= Gem::Version.new("2.3.0")) - end -end