diff --git a/Gemfile b/Gemfile index b71fd00caf..e4314d81f8 100644 --- a/Gemfile +++ b/Gemfile @@ -58,7 +58,7 @@ gem 'kaminari', '~> 0.17.0' gem 'andand' gem 'angularjs-rails', '1.5.5' -gem 'aws-sdk', '1.11.1' # temporarily locked down due to https://github.com/aws/aws-sdk-ruby/issues/273 +gem 'aws-sdk', '1.67.0' gem 'bugsnag' gem 'db2fog' gem 'haml' diff --git a/Gemfile.lock b/Gemfile.lock index 5989a817e5..d87a2ebb5b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -117,10 +117,11 @@ GEM awesome_nested_set (3.2.1) activerecord (>= 4.0.0, < 7.0) awesome_print (1.8.0) - aws-sdk (1.11.1) + aws-sdk (1.67.0) + aws-sdk-v1 (= 1.67.0) + aws-sdk-v1 (1.67.0) json (~> 1.4) - nokogiri (>= 1.4.4) - uuidtools (~> 2.1) + nokogiri (~> 1) bcrypt (3.1.13) bugsnag (6.18.0) concurrent-ruby (~> 1.0) @@ -648,7 +649,6 @@ GEM unicorn-worker-killer (0.4.4) get_process_mem (~> 0) unicorn (>= 4, < 6) - uuidtools (2.1.5) warden (1.2.7) rack (>= 1.0) webdrivers (4.2.0) @@ -688,7 +688,7 @@ DEPENDENCIES atomic awesome_nested_set (~> 3.2.1) awesome_print - aws-sdk (= 1.11.1) + aws-sdk (= 1.67.0) bugsnag byebug (~> 11.0.0) cancan (~> 1.6.10) diff --git a/app/models/spree/image.rb b/app/models/spree/image.rb index 8af54e443b..24d20aeb93 100644 --- a/app/models/spree/image.rb +++ b/app/models/spree/image.rb @@ -50,26 +50,36 @@ module Spree false end - def self.set_attachment_attributes(attribute_name, attribute_value) + def self.set_attachment_attribute(attribute_name, attribute_value) attachment_definitions[:attachment][attribute_name] = attribute_value end - def self.set_s3_attachment_definitions + def self.set_storage_attachment_attributes if Spree::Config[:use_s3] - set_attachment_attributes(:storage, :s3) - set_attachment_attributes(:s3_credentials, s3_credentials) - set_attachment_attributes(:s3_headers, - ActiveSupport::JSON.decode(Spree::Config[:s3_headers])) - set_attachment_attributes(:bucket, Spree::Config[:s3_bucket]) + set_s3_attachment_attributes else - attachment_definitions[:attachment].delete :storage + attachment_definitions[:attachment].delete(:storage) end end + def self.set_s3_attachment_attributes + set_attachment_attribute(:storage, :s3) + set_attachment_attribute(:s3_credentials, s3_credentials) + set_attachment_attribute(:s3_headers, + ActiveSupport::JSON.decode(Spree::Config[:s3_headers])) + set_attachment_attribute(:bucket, Spree::Config[:s3_bucket]) + + # We use :s3_alias_url (virtual host url style) and set the URL on property s3_host_alias + set_attachment_attribute(:s3_host_alias, attachment_definitions[:attachment][:url]) + set_attachment_attribute(:url, ":s3_alias_url") + end + private_class_method :set_s3_attachment_attributes + def self.s3_credentials { access_key_id: Spree::Config[:s3_access_key], secret_access_key: Spree::Config[:s3_secret], bucket: Spree::Config[:s3_bucket] } end + private_class_method :s3_credentials end end diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index c91497b27a..56f2e3325c 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -37,9 +37,9 @@ Spree.config do |config| end # Attachments settings -Spree::Image.set_attachment_attributes(:path, ENV['ATTACHMENT_PATH']) if ENV['ATTACHMENT_PATH'] -Spree::Image.set_attachment_attributes(:url, ENV['ATTACHMENT_URL']) if ENV['ATTACHMENT_URL'] -Spree::Image.set_s3_attachment_definitions +Spree::Image.set_attachment_attribute(:path, ENV['ATTACHMENT_PATH']) if ENV['ATTACHMENT_PATH'] +Spree::Image.set_attachment_attribute(:url, ENV['ATTACHMENT_URL']) if ENV['ATTACHMENT_URL'] +Spree::Image.set_storage_attachment_attributes # Spree 2.0 recommends explicitly setting this here when using spree_auth_devise Spree.user_class = 'Spree::User'