mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: allow specifying s3 config via globals
This refactors handling of s3 so it can be specified via GlobalSetting This means that in a multisite environment you can configure s3 uploads without actual sites knowing credentials in s3 It is a critical setting for situations where assets are mirrored to s3.
This commit is contained in:
@@ -118,6 +118,43 @@ class SiteSetting < ActiveRecord::Base
|
||||
def self.attachment_filename_blacklist_regex
|
||||
@attachment_filename_blacklist_regex ||= Regexp.union(SiteSetting.attachment_filename_blacklist.split("|"))
|
||||
end
|
||||
|
||||
# helpers for getting s3 settings that fallback to global
|
||||
class Upload
|
||||
def self.s3_cdn_url
|
||||
SiteSetting.enable_s3_uploads ? SiteSetting.s3_cdn_url : GlobalSetting.s3_cdn_url
|
||||
end
|
||||
|
||||
def self.s3_region
|
||||
SiteSetting.enable_s3_uploads ? SiteSetting.s3_region : GlobalSetting.s3_region
|
||||
end
|
||||
|
||||
def self.s3_upload_bucket
|
||||
SiteSetting.enable_s3_uploads ? SiteSetting.s3_upload_bucket : GlobalSetting.s3_bucket
|
||||
end
|
||||
|
||||
def self.enable_s3_uploads
|
||||
SiteSetting.enable_s3_uploads || GlobalSetting.use_s3?
|
||||
end
|
||||
|
||||
def self.absolute_base_url
|
||||
bucket = SiteSetting.enable_s3_uploads ? Discourse.store.s3_bucket_name : GlobalSetting.s3_bucket
|
||||
|
||||
# cf. http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
|
||||
if SiteSetting.Upload.s3_region == "us-east-1"
|
||||
"//#{bucket}.s3.amazonaws.com"
|
||||
elsif SiteSetting.Upload.s3_region == 'cn-north-1'
|
||||
"//#{bucket}.s3.cn-north-1.amazonaws.com.cn"
|
||||
else
|
||||
"//#{bucket}.s3-#{SiteSetting.Upload.s3_region}.amazonaws.com"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.Upload
|
||||
SiteSetting::Upload
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
||||
Reference in New Issue
Block a user