FIX: S3 endpoint broke bucket creation in non-default region

This commit is contained in:
Gerhard Schlager 2019-02-05 17:50:27 +01:00 committed by Neil Lalonde
parent 12cf3320c2
commit d576a3fa57
4 changed files with 6 additions and 5 deletions

View File

@ -152,7 +152,7 @@ class SiteSetting < ActiveRecord::Base
bucket = SiteSetting.enable_s3_uploads ? Discourse.store.s3_bucket_name : GlobalSetting.s3_bucket_name
# cf. http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
if SiteSetting.s3_endpoint == "https://s3.amazonaws.com"
if SiteSetting.s3_endpoint.blank? || SiteSetting.s3_endpoint.end_with?("amazonaws.com")
if SiteSetting.Upload.s3_region.start_with?("cn-")
"//#{bucket}.s3.#{SiteSetting.Upload.s3_region}.amazonaws.com.cn"
else

View File

@ -1484,7 +1484,7 @@ en:
automatic_backups_enabled: "Run automatic backups as defined in backup frequency"
backup_frequency: "The number of days between backups."
s3_backup_bucket: "The remote bucket to hold backups. WARNING: Make sure it is a private bucket."
s3_endpoint: "The endpoint can be modified to backup to an S3 compatible service like DigitalOcean Spaces or Minio. WARNING: Use default if using AWS S3"
s3_endpoint: "The endpoint can be modified to backup to an S3 compatible service like DigitalOcean Spaces or Minio. WARNING: Leave blank if using AWS S3."
s3_force_path_style: "Enforce path-style addressing for your custom endpoint. IMPORTANT: Required for using Minio uploads and backups."
s3_configure_tombstone_policy: "Enable automatic deletion policy for tombstone uploads. IMPORTANT: If disabled, no space will be reclaimed after uploads are deleted."
s3_disable_cleanup: "Disable the removal of backups from S3 when removed locally."
@ -1540,7 +1540,7 @@ en:
s3_upload_bucket: "The Amazon S3 bucket name that files will be uploaded into. WARNING: must be lowercase, no periods, no underscores."
s3_access_key_id: "The Amazon S3 access key id that will be used to upload images."
s3_secret_access_key: "The Amazon S3 secret access key that will be used to upload images."
s3_region: "The Amazon S3 region name that will be used to upload images."
s3_region: "The Amazon S3 region name that will be used to upload images and backups."
s3_cdn_url: "The CDN URL to use for all s3 assets (for example: https://cdn.somewhere.com). WARNING: after changing this setting you must rebake all old posts."
avatar_sizes: "List of automatically generated avatar sizes."

View File

@ -1038,7 +1038,7 @@ files:
default: ""
regex: '^[a-z0-9\-\/]+$' # can't use '.' when using HTTPS
s3_endpoint:
default: "https://s3.amazonaws.com"
default: ""
regex: '^https?:\/\/.+[^\/]$'
shadowed_by_global: true
s3_cdn_url:

View File

@ -193,10 +193,11 @@ class S3Helper
def self.s3_options(obj)
opts = {
region: obj.s3_region,
endpoint: SiteSetting.s3_endpoint,
force_path_style: SiteSetting.s3_force_path_style
}
opts[:endpoint] = SiteSetting.s3_endpoint if SiteSetting.s3_endpoint.present?
unless obj.s3_use_iam_profile
opts[:access_key_id] = obj.s3_access_key_id
opts[:secret_access_key] = obj.s3_secret_access_key