[ENV] Add fog config

This commit is contained in:
Paul Chavard 2018-08-22 17:36:15 +02:00
parent db8e750f1a
commit 296e3a9b09
5 changed files with 29 additions and 18 deletions

View file

@ -4,6 +4,12 @@ class RemoteDownloader
end
def url
@url ||= File.join(STORAGE_URL, @filename)
@url ||= File.join(base_url, CarrierWave::Uploader::Base.fog_directory, @filename)
end
protected
def base_url
Rails.application.secrets.fog[:base_url]
end
end

View file

@ -23,7 +23,7 @@ Flipflop.configure do
group :production do
feature :remote_storage,
default: Rails.env.production? || Rails.env.staging?
default: ENV['FOG_ENABLED'] == 'enabled'
feature :weekly_overview,
default: Rails.env.production?
end

View file

@ -1,17 +1,18 @@
if Rails.env.test?
Fog.credentials_path = Rails.root.join('config', 'fog_credentials.test.yml')
else
Fog.credentials_path = Rails.root.join('config', 'fog_credentials.yml')
end
CarrierWave.configure do |config|
# These permissions will make dir and files available only to the user running
# the servers
config.permissions = 0664
config.directory_permissions = 0775
if Rails.env.production? || Rails.env.staging?
config.fog_credentials = { provider: 'OpenStack' }
if ENV['FOG_ENABLED'] == 'enabled'
config.fog_credentials = {
provider: 'OpenStack',
openstack_tenant: Rails.application.secrets.fog[:openstack_tenant],
openstack_api_key: Rails.application.secrets.fog[:openstack_api_key],
openstack_username: Rails.application.secrets.fog[:openstack_username],
openstack_auth_url: Rails.application.secrets.fog[:openstack_auth_url],
openstack_region: Rails.application.secrets.fog[:openstack_region],
}
end
# This avoids uploaded files from saving to public/ and so
@ -22,11 +23,5 @@ CarrierWave.configure do |config|
config.fog_public = true
if Rails.env.production?
config.fog_directory = "tps"
elsif Rails.env.development?
config.fog_directory = "test_local"
else
config.fog_directory = "tps_dev"
end
config.fog_directory = Rails.application.secrets.fog[:directory]
end

View file

@ -1 +0,0 @@
STORAGE_URL = "https://storage.apientreprise.fr/#{CarrierWave::Uploader::Base.fog_directory}/"

View file

@ -31,6 +31,14 @@ defaults: &defaults
api_entreprise:
key: <%= ENV['API_ENTREPRISE_KEY'] %>
base_url: <%= ENV['API_ENTREPRISE_BASE_URL'] %>
fog:
openstack_tenant: <%= ENV['FOG_OPENSTACK_TENANT'] %>
openstack_api_key: <%= ENV['FOG_OPENSTACK_API_KEY'] %>
openstack_username: <%= ENV['FOG_OPENSTACK_USERNAME'] %>
openstack_auth_url: <%= ENV['FOG_OPENSTACK_AUTH_URL'] %>
openstack_region: <%= ENV['FOG_OPENSTACK_REGION'] %>
base_url: <% ENV['FOG_BASE_URL'] %>
directory: <%= ENV['FOG_DIRECTORY'] %>
development:
<<: *defaults
@ -42,6 +50,9 @@ test:
api_entreprise:
key: api_entreprise_test_key
base_url: https://entreprise.api.gouv.fr/v2
fog:
base_url: https://storage.apientreprise.fr
directory: tps_dev
france_connect_particulier:
identifier: france_connect_test_identifier
secret: france_connect_test_secret