mirror of
https://github.com/discourse/discourse.git
synced 2024-12-04 19:33:41 +08:00
0568d36133
When we added direct S3 uploads to Discourse, which use presigned URLs, we never took into account the dualstack endpoints for IPv6 on S3. This commit fixes the issue by using the dualstack endpoints for presigned URLs and requests, which are used in the get-presigned-put and batch-presign-urls endpoints used when directly uploading to S3. It also makes regular S3 requests for `put` and so on use dualstack URLs. It doesn't seem like there is a downside to doing this, but a bunch of specs needed to be updated to reflect this.
41 lines
1.1 KiB
Ruby
41 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module UploadsHelpers
|
|
def setup_s3
|
|
SiteSetting.enable_s3_uploads = true
|
|
|
|
SiteSetting.s3_region = "us-west-1"
|
|
SiteSetting.s3_upload_bucket = "s3-upload-bucket"
|
|
|
|
SiteSetting.s3_access_key_id = "some key"
|
|
SiteSetting.s3_secret_access_key = "some secrets3_region key"
|
|
|
|
dualstack = SiteSetting.Upload.use_dualstack_endpoint ? ".dualstack" : ""
|
|
|
|
stub_request(
|
|
:head,
|
|
"https://#{SiteSetting.s3_upload_bucket}.s3#{dualstack}.#{SiteSetting.s3_region}.amazonaws.com/",
|
|
)
|
|
end
|
|
|
|
def enable_secure_uploads
|
|
setup_s3
|
|
SiteSetting.secure_uploads = true
|
|
end
|
|
|
|
def stub_upload(upload)
|
|
dualstack = SiteSetting.Upload.use_dualstack_endpoint ? ".dualstack" : ""
|
|
|
|
url =
|
|
%r{https://#{SiteSetting.s3_upload_bucket}.s3#{dualstack}.#{SiteSetting.s3_region}.amazonaws.com/original/\d+X.*#{upload.sha1}.#{upload.extension}\?acl}
|
|
stub_request(:put, url)
|
|
end
|
|
|
|
def stub_s3_store
|
|
store = FileStore::S3Store.new
|
|
client = Aws::S3::Client.new(stub_responses: true)
|
|
store.s3_helper.stubs(:s3_client).returns(client)
|
|
Discourse.stubs(:store).returns(store)
|
|
end
|
|
end
|