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
path: root/lib/api
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
parent2242221252d13fdf322b5e59f971a689831c541b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/files.rb13
-rw-r--r--lib/api/helpers.rb15
2 files changed, 15 insertions, 13 deletions
diff --git a/lib/api/files.rb b/lib/api/files.rb
index b02f1a8728b..18638abd184 100644
--- a/lib/api/files.rb
+++ b/lib/api/files.rb
@@ -151,19 +151,6 @@ module API
present blame_ranges, with: Entities::BlameRange
end
- desc 'Get raw file metadata from repository'
- params do
- requires :file_path, type: String, file_path: true,
- desc: 'The url encoded path to the file.', documentation: { example: 'lib%2Fclass%2Erb' }
- optional :ref, type: String,
- desc: 'The name of branch, tag or commit', allow_blank: false, documentation: { example: 'main' }
- end
- head ":id/repository/files/:file_path/raw", requirements: FILE_ENDPOINT_REQUIREMENTS, urgency: :low do
- assign_file_vars!
-
- set_http_headers(blob_data)
- end
-
desc 'Get raw file contents from the repository' do
success File
end
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)