From 97e17fe084d493655d1542495ffa494fd9003a08 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Sun, 20 Jan 2019 20:44:07 +0530 Subject: [PATCH] FIX: Use ENV values instead of 'S3Helper.s3_options' in migrate_to_s3 This commit makes the rake task operational for all regions for s3. If we declare s3_endpoint as https://s3.amazonaws.com while creating an instance of Aws::S3::Client, head_bucket fails for all s3 regions apart from us-east-1. The commit manually defines all parameters for Aws::S3::Client apart from s3_endpoint to bypass this problem make this task usable for AWS S3. Removing s3_endpoint from the payload means that custom endpoints like Minio/DO Spaces for will not work in the meantime and we'll have to add support for a custom `s3_endpoint` in the future. This commit follows up on 60790eb0. --- lib/tasks/uploads.rake | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake index 37b5425529..cb99d69daf 100644 --- a/lib/tasks/uploads.rake +++ b/lib/tasks/uploads.rake @@ -244,14 +244,18 @@ def migrate_to_s3 exit 3 end - bucket_has_folder_path = true if GlobalSetting.s3_bucket.include? "/" - s3 = Aws::S3::Client.new(S3Helper.s3_options(GlobalSetting)) + bucket_has_folder_path = true if ENV["DISCOURSE_S3_BUCKET"].include? "/" + + s3 = Aws::S3::Client.new( + region: ENV["DISCOURSE_S3_REGION"], + access_key_id: ENV["DISCOURSE_S3_ACCESS_KEY_ID"], + secret_access_key: ENV["DISCOURSE_S3_SECRET_ACCESS_KEY"]) if bucket_has_folder_path - bucket, folder = S3Helper.get_bucket_and_folder_path(GlobalSetting.s3_bucket) + bucket, folder = S3Helper.get_bucket_and_folder_path(ENV["DISCOURSE_S3_BUCKET"]) folder = File.join(folder, "/") else - bucket, folder = GlobalSetting.s3_bucket, "" + bucket, folder = ENV["DISCOURSE_S3_BUCKET"], "" end begin