Commit e18f915a authored by Vladimir Shushlin's avatar Vladimir Shushlin

Backport expire_at from carrierwave 2.1.* to patch

We want to use custom expire_at for pages object storage links

* https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40361/diffs
* https://gitlab.com/groups/gitlab-org/-/epics/3901

Since this method is patched in gitlab codebase, we need to also
backport
https://github.com/carrierwaveuploader/carrierwave/commit/
64aab24f57e4e1f7489e9faa37d6782818c164cc

This can be safely removed once we update carrierwave to > 2.1.0
parent 7e0e3508
......@@ -7,7 +7,9 @@ require "carrierwave/storage/fog"
#
# This patch also incorporates
# https://github.com/carrierwaveuploader/carrierwave/pull/2375 to
# provide Azure support. This is already in CarrierWave v2.1.x, but
# provide Azure support
# and https://github.com/carrierwaveuploader/carrierwave/pull/2397 to
# support custom expire_at. This is already in CarrierWave v2.1.x, but
# upgrading this gem is a significant task:
# https://gitlab.com/gitlab-org/gitlab/-/issues/216067
module CarrierWave
......@@ -28,7 +30,7 @@ module CarrierWave
# avoid a get by using local references
local_directory = connection.directories.new(key: @uploader.fog_directory)
local_file = local_directory.files.new(key: path)
expire_at = ::Fog::Time.now + @uploader.fog_authenticated_url_expiration
expire_at = options[:expire_at] || ::Fog::Time.now + @uploader.fog_authenticated_url_expiration
case @uploader.fog_credentials[:provider]
when 'AWS', 'Google'
# Older versions of fog-google do not support options as a parameter
......
......@@ -28,5 +28,17 @@ RSpec.describe 'CarrierWave::Storage::Fog::File' do
expect(subject.authenticated_url).to eq("https://sa.blob.core.windows.net/test_container/test_blob?token")
end
end
context 'with custom expire_at' do
it 'properly sets expires param' do
expire_at = 24.hours.from_now
expect_next_instance_of(Fog::Storage::AzureRM::File) do |file|
expect(file).to receive(:url).with(expire_at).and_call_original
end
expect(subject.authenticated_url(expire_at: expire_at)).to eq("https://sa.blob.core.windows.net/test_container/test_blob?token")
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment