Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-05 03:07:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-05 03:07:14 +0300
commit86af4d6a04a1c30ebfe2377cdc3270ade911b2fe (patch)
tree37df9fde7aee7b97d088afe2073c67b9114af53f /lib/api/helpers.rb
parent2242221252d13fdf322b5e59f971a689831c541b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r--lib/api/helpers.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 95c81c14bf9..38430aac455 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -608,6 +608,8 @@ module API
if file.file_storage?
present_disk_file!(file.path, file.filename)
elsif supports_direct_download && file.class.direct_download_enabled?
+ return redirect(signed_head_url(file)) if head_request_on_aws_file?(file)
+
redirect(cdn_fronted_url(file))
else
header(*Gitlab::Workhorse.send_url(file.url))
@@ -707,6 +709,19 @@ module API
private
+ def head_request_on_aws_file?(file)
+ request.head? && file.fog_credentials[:provider] == 'AWS'
+ end
+
+ def signed_head_url(file)
+ fog_storage = ::Fog::Storage.new(file.fog_credentials)
+ fog_dir = fog_storage.directories.new(key: file.fog_directory)
+ fog_file = fog_dir.files.new(key: file.path)
+ expire_at = ::Fog::Time.now + file.fog_authenticated_url_expiration
+
+ fog_file.collection.head_url(fog_file.key, expire_at)
+ end
+
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def initial_current_user
return @initial_current_user if defined?(@initial_current_user)