about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdam Thurlow <thurloat@gmail.com>2017-09-05 18:17:06 -0300
committerEugen Rochko <eugen@zeonfederated.com>2017-09-05 23:17:06 +0200
commit6994664a1391d6a027caec3d5ca9e022f41a0711 (patch)
treef0ecba66e42c7eac50f079365c416fc28b3b7d52
parentbe7ffa2d7539d5a1946a3933cb9d242b9fac0ddc (diff)
swift-enable the paperclip! :paperclip: (#2322)
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock15
-rw-r--r--app/helpers/routing_helper.rb8
-rw-r--r--config/initializers/ostatus.rb1
-rw-r--r--config/initializers/paperclip.rb15
5 files changed, 39 insertions, 1 deletions
diff --git a/Gemfile b/Gemfile
index ae90697f1..486e72cc4 100644
--- a/Gemfile
+++ b/Gemfile
@@ -15,6 +15,7 @@ gem 'pghero', '~> 1.7'
 gem 'dotenv-rails', '~> 2.2'
 
 gem 'aws-sdk', '~> 2.9'
+gem 'fog-openstack', '~> 0.1'
 gem 'paperclip', '~> 5.1'
 gem 'paperclip-av-transcoder', '~> 0.6'
 
diff --git a/Gemfile.lock b/Gemfile.lock
index 4a3f20e09..ef99e0d7b 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -154,12 +154,25 @@ GEM
     erubis (2.7.0)
     et-orbi (1.0.5)
       tzinfo
+    excon (0.58.0)
     execjs (2.7.0)
     fabrication (2.16.2)
     faker (1.7.3)
       i18n (~> 0.5)
     fast_blank (1.0.0)
     ffi (1.9.18)
+    fog-core (1.45.0)
+      builder
+      excon (~> 0.58)
+      formatador (~> 0.2)
+    fog-json (1.0.2)
+      fog-core (~> 1.0)
+      multi_json (~> 1.10)
+    fog-openstack (0.1.21)
+      fog-core (>= 1.40)
+      fog-json (>= 1.0)
+      ipaddress (>= 0.8)
+    formatador (0.2.5)
     fuubar (2.2.0)
       rspec-core (~> 3.0)
       ruby-progressbar (~> 1.4)
@@ -211,6 +224,7 @@ GEM
       rainbow (~> 2.2)
       terminal-table (>= 1.5.1)
     idn-ruby (0.1.0)
+    ipaddress (0.8.3)
     jmespath (1.3.1)
     json (2.1.0)
     json-ld (2.1.5)
@@ -535,6 +549,7 @@ DEPENDENCIES
   fabrication (~> 2.16)
   faker (~> 1.7)
   fast_blank (~> 1.0)
+  fog-openstack (~> 0.1)
   fuubar (~> 2.2)
   goldfinger (~> 2.0)
   hamlit-rails (~> 0.2)
diff --git a/app/helpers/routing_helper.rb b/app/helpers/routing_helper.rb
index 1fbf77ec3..f4693358c 100644
--- a/app/helpers/routing_helper.rb
+++ b/app/helpers/routing_helper.rb
@@ -12,8 +12,14 @@ module RoutingHelper
   end
 
   def full_asset_url(source, options = {})
-    source = ActionController::Base.helpers.asset_url(source, options) unless Rails.configuration.x.use_s3
+    source = ActionController::Base.helpers.asset_url(source, options) unless use_storage?
 
     URI.join(root_url, source).to_s
   end
+
+  private
+
+  def use_storage?
+    Rails.configuration.x.use_s3 || Rails.configuration.x.use_swift
+  end
 end
diff --git a/config/initializers/ostatus.rb b/config/initializers/ostatus.rb
index a885545f8..c00aba0de 100644
--- a/config/initializers/ostatus.rb
+++ b/config/initializers/ostatus.rb
@@ -12,6 +12,7 @@ Rails.application.configure do
   config.x.web_domain   = web_host
   config.x.use_https    = https
   config.x.use_s3       = ENV['S3_ENABLED'] == 'true'
+  config.x.use_swift    = ENV['SWIFT_ENABLED'] == 'true'
 
   config.x.alternate_domains = alternate_domains.split(/\s*,\s*/)
 
diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb
index 740c1a953..e9f455251 100644
--- a/config/initializers/paperclip.rb
+++ b/config/initializers/paperclip.rb
@@ -40,6 +40,21 @@ if ENV['S3_ENABLED'] == 'true'
     Paperclip::Attachment.default_options[:url]           = ':s3_alias_url'
     Paperclip::Attachment.default_options[:s3_host_alias] = ENV['S3_CLOUDFRONT_HOST']
   end
+elsif ENV['SWIFT_ENABLED'] == 'true'
+  Paperclip::Attachment.default_options.merge!(
+    path: ':class/:attachment/:id_partition/:style/:filename',
+    storage: :fog,
+    fog_credentials: {
+      provider: 'OpenStack',
+      openstack_username: ENV.fetch('SWIFT_USERNAME'),
+      openstack_tenant: ENV.fetch('SWIFT_TENANT'),
+      openstack_api_key: ENV.fetch('SWIFT_PASSWORD'),
+      openstack_auth_url: ENV.fetch('SWIFT_AUTH_URL'),
+    },
+    fog_directory: ENV.fetch('SWIFT_CONTAINER'),
+    fog_host: ENV.fetch('SWIFT_OBJECT_URL'),
+    fog_public: true
+  )
 else
   Paperclip::Attachment.default_options[:path] = (ENV['PAPERCLIP_ROOT_PATH'] || ':rails_root/public/system') + '/:class/:attachment/:id_partition/:style/:filename'
   Paperclip::Attachment.default_options[:url]  = (ENV['PAPERCLIP_ROOT_URL'] || '/system') + '/:class/:attachment/:id_partition/:style/:filename'