Skip to content

Commit

Permalink
FIX: S3 endpoint broke bucket creation in non-default region
Browse files Browse the repository at this point in the history
  • Loading branch information
gschlager authored and nlalonde committed Feb 7, 2019
1 parent 12cf332 commit d576a3f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/site_setting.rb
Expand Up @@ -152,7 +152,7 @@ def self.absolute_base_url
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
Expand Down
4 changes: 2 additions & 2 deletions config/locales/server.en.yml
Expand Up @@ -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."
Expand Down Expand Up @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion config/site_settings.yml
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion lib/s3_helper.rb
Expand Up @@ -193,10 +193,11 @@ def object(path)
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
Expand Down

0 comments on commit d576a3f

Please sign in to comment.