debian-mirror-gitlab/config/initializers/carrierwave.rb

44 lines
1.5 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/
aws_file = Rails.root.join('config', 'aws.yml')
2016-06-02 11:05:42 +05:30
if File.exist?(aws_file)
2014-09-02 18:07:02 +05:30
AWS_CONFIG = YAML.load(File.read(aws_file))[Rails.env]
CarrierWave.configure do |config|
2017-08-17 22:00:37 +05:30
config.fog_provider = 'fog/aws'
2014-09-02 18:07:02 +05:30
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: AWS_CONFIG['access_key_id'], # required
aws_secret_access_key: AWS_CONFIG['secret_access_key'], # required
region: AWS_CONFIG['region'], # optional, defaults to 'us-east-1'
}
2015-04-26 12:48:37 +05:30
# required
config.fog_directory = AWS_CONFIG['bucket']
# optional, defaults to true
config.fog_public = false
# optional, defaults to {}
2016-06-02 11:05:42 +05:30
config.fog_attributes = { 'Cache-Control' => 'max-age=315576000' }
2015-04-26 12:48:37 +05:30
# optional time (in seconds) that authenticated urls will be valid.
# when fog_public is false and provider is AWS or Google, defaults to 600
config.fog_authenticated_url_expiration = 1 << 29
2014-09-02 18:07:02 +05:30
end
# Mocking Fog requests, based on: https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Test-Fog-based-uploaders
if Rails.env.test?
Fog.mock!
connection = ::Fog::Storage.new(
2015-12-23 02:04:40 +05:30
aws_access_key_id: AWS_CONFIG['access_key_id'],
aws_secret_access_key: AWS_CONFIG['secret_access_key'],
provider: 'AWS',
region: AWS_CONFIG['region']
)
2015-04-26 12:48:37 +05:30
connection.directories.create(key: AWS_CONFIG['bucket'])
2014-09-02 18:07:02 +05:30
end
end