mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: Check options and not just site settings.
This commit is contained in:
parent
79c1d3459b
commit
78bec20424
1 changed files with 13 additions and 5 deletions
|
@ -2,8 +2,10 @@ require "aws-sdk"
|
||||||
|
|
||||||
class S3Helper
|
class S3Helper
|
||||||
|
|
||||||
def initialize(s3_upload_bucket, tombstone_prefix='', s3_options=default_s3_options)
|
class SettingMissing < StandardError; end
|
||||||
@s3_options = s3_options
|
|
||||||
|
def initialize(s3_upload_bucket, tombstone_prefix='', options={})
|
||||||
|
@s3_options = default_s3_options.merge(options)
|
||||||
|
|
||||||
@s3_bucket, @s3_bucket_folder_path = begin
|
@s3_bucket, @s3_bucket_folder_path = begin
|
||||||
raise Discourse::InvalidParameters.new("s3_bucket") if s3_upload_bucket.blank?
|
raise Discourse::InvalidParameters.new("s3_bucket") if s3_upload_bucket.blank?
|
||||||
|
@ -16,6 +18,8 @@ class S3Helper
|
||||||
else
|
else
|
||||||
tombstone_prefix
|
tombstone_prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
|
check_missing_options
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload(file, path, options={})
|
def upload(file, path, options={})
|
||||||
|
@ -70,9 +74,6 @@ class S3Helper
|
||||||
opts = { region: SiteSetting.s3_region }
|
opts = { region: SiteSetting.s3_region }
|
||||||
|
|
||||||
unless SiteSetting.s3_use_iam_profile
|
unless SiteSetting.s3_use_iam_profile
|
||||||
raise Discourse::SiteSettingMissing.new("s3_access_key_id") if SiteSetting.s3_access_key_id.blank?
|
|
||||||
raise Discourse::SiteSettingMissing.new("s3_secret_access_key") if SiteSetting.s3_secret_access_key.blank?
|
|
||||||
|
|
||||||
opts[:access_key_id] = SiteSetting.s3_access_key_id
|
opts[:access_key_id] = SiteSetting.s3_access_key_id
|
||||||
opts[:secret_access_key] = SiteSetting.s3_secret_access_key
|
opts[:secret_access_key] = SiteSetting.s3_secret_access_key
|
||||||
end
|
end
|
||||||
|
@ -89,4 +90,11 @@ class S3Helper
|
||||||
bucket.create unless bucket.exists?
|
bucket.create unless bucket.exists?
|
||||||
bucket
|
bucket
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_missing_options
|
||||||
|
unless SiteSetting.s3_use_iam_profile
|
||||||
|
raise SettingMissing.new("access_key_id") if @s3_options[:access_key_id].blank?
|
||||||
|
raise SettingMissing.new("secret_access_key") if @s3_options[:secret_access_key].blank?
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue