about summary refs log tree commit diff
path: root/config
diff options
context:
space:
mode:
authorYamagishi Kazutoshi <ykzts@desire.sh>2017-12-09 08:47:52 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-12-09 00:47:52 +0100
commitb0db4dad79dac4d9d339e09c62d5aaae9e56c861 (patch)
tree9ea17bcdaf94bca97264eb36326557825051ecc3 /config
parentdad0a096752ca2aed0a12d5fa6f4443124804e7c (diff)
Revert fog-aws (ref #5604) (#5934)
Diffstat (limited to 'config')
-rw-r--r--config/initializers/paperclip.rb47
1 files changed, 26 insertions, 21 deletions
diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb
index 14bd034e6..bd26c533d 100644
--- a/config/initializers/paperclip.rb
+++ b/config/initializers/paperclip.rb
@@ -14,40 +14,45 @@ Paperclip::Attachment.default_options.merge!(
 )
 
 if ENV['S3_ENABLED'] == 'true'
-  require 'fog/aws'
+  require 'aws-sdk'
+  Aws.eager_autoload!(services: %w(S3))
 
-  s3_protocol           = ENV.fetch('S3_PROTOCOL') { 'https' }
-  s3_hostname           = ENV.fetch('S3_HOSTNAME') { "s3-#{ENV['S3_REGION']}.amazonaws.com" }
-  aws_signature_version = ENV['S3_SIGNATURE_VERSION'] == 's3' ? 2 : ENV['S3_SIGNATURE_VERSION'].to_i
-  aws_signature_version = 4 if aws_signature_version.zero?
+  s3_region   = ENV.fetch('S3_REGION')   { 'us-east-1' }
+  s3_protocol = ENV.fetch('S3_PROTOCOL') { 'https' }
+  s3_hostname = ENV.fetch('S3_HOSTNAME') { "s3-#{s3_region}}.amazonaws.com" }
 
   Paperclip::Attachment.default_options.merge!(
-    fog_credentials: {
-      provider: 'AWS',
-      aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
-      aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
-      aws_signature_version: aws_signature_version,
-      region: ENV.fetch('S3_REGION') { 'us-east-1' },
-      scheme: s3_protocol,
-      host: s3_hostname
+    storage: :s3,
+    s3_protocol: s3_protocol,
+    s3_host_name: s3_hostname,
+    s3_headers: {
+      'Cache-Control' => 'max-age=315576000',
+    },
+    s3_permissions: ENV.fetch('S3_PERMISSION') { 'public-read' },
+    s3_region: s3_region,
+    s3_credentials: {
+      bucket: ENV['S3_BUCKET'],
+      access_key_id: ENV['AWS_ACCESS_KEY_ID'],
+      secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
     },
-    fog_directory: ENV['S3_BUCKET'],
-    fog_options: {
-      acl: ENV.fetch('S3_PERMISSION') { 'public-read' },
-      cache_control: 'max-age=315576000',
+    s3_options: {
+      signature_version: ENV.fetch('S3_SIGNATURE_VERSION') { 'v4' },
     }
   )
 
   if ENV.has_key?('S3_ENDPOINT')
-    Paperclip::Attachment.default_options[:fog_credentials].merge!(
+    Paperclip::Attachment.default_options[:s3_options].merge!(
       endpoint: ENV['S3_ENDPOINT'],
-      path_style: true
+      force_path_style: true
     )
-    Paperclip::Attachment.default_options[:fog_host] = "#{s3_protocol}://#{s3_hostname}/#{ENV['S3_BUCKET']}"
+    Paperclip::Attachment.default_options[:url] = ':s3_path_url'
   end
 
   if ENV.has_key?('S3_CLOUDFRONT_HOST')
-    Paperclip::Attachment.default_options[:fog_host] = "#{s3_protocol}://#{ENV['S3_CLOUDFRONT_HOST']}"
+    Paperclip::Attachment.default_options.merge!(
+      url: ':s3_alias_url',
+      s3_host_alias: ENV['S3_CLOUDFRONT_HOST']
+    )
   end
 elsif ENV['SWIFT_ENABLED'] == 'true'
   require 'fog/openstack'