diff options
Diffstat (limited to 'app/services/projects')
-rw-r--r-- | app/services/projects/lfs_pointers/lfs_download_link_list_service.rb | 2 | ||||
-rw-r--r-- | app/services/projects/lfs_pointers/lfs_download_service.rb | 14 |
2 files changed, 11 insertions, 5 deletions
diff --git a/app/services/projects/lfs_pointers/lfs_download_link_list_service.rb b/app/services/projects/lfs_pointers/lfs_download_link_list_service.rb index efd410088ab..c82ed97203f 100644 --- a/app/services/projects/lfs_pointers/lfs_download_link_list_service.rb +++ b/app/services/projects/lfs_pointers/lfs_download_link_list_service.rb @@ -81,11 +81,13 @@ module Projects def parse_response_links(objects_response) objects_response.each_with_object([]) do |entry, link_list| link = entry.dig('actions', DOWNLOAD_ACTION, 'href') + headers = entry.dig('actions', DOWNLOAD_ACTION, 'header') raise DownloadLinkNotFound unless link link_list << LfsDownloadObject.new(oid: entry['oid'], size: entry['size'], + headers: headers, link: add_credentials(link)) rescue DownloadLinkNotFound, Addressable::URI::InvalidURIError log_error("Link for Lfs Object with oid #{entry['oid']} not found or invalid.") diff --git a/app/services/projects/lfs_pointers/lfs_download_service.rb b/app/services/projects/lfs_pointers/lfs_download_service.rb index 525f8a25d04..9e2edf7c4ef 100644 --- a/app/services/projects/lfs_pointers/lfs_download_service.rb +++ b/app/services/projects/lfs_pointers/lfs_download_service.rb @@ -11,7 +11,7 @@ module Projects LARGE_FILE_SIZE = 1.megabytes attr_reader :lfs_download_object - delegate :oid, :size, :credentials, :sanitized_url, to: :lfs_download_object, prefix: :lfs + delegate :oid, :size, :credentials, :sanitized_url, :headers, to: :lfs_download_object, prefix: :lfs def initialize(project, lfs_download_object) super(project) @@ -71,17 +71,21 @@ module Projects raise_oid_error! if digester.hexdigest != lfs_oid end - def download_headers - { stream_body: true }.tap do |headers| + def download_options + http_options = { headers: lfs_headers, stream_body: true } + + return http_options if lfs_download_object.has_authorization_header? + + http_options.tap do |options| if lfs_credentials[:user].present? || lfs_credentials[:password].present? # Using authentication headers in the request - headers[:basic_auth] = { username: lfs_credentials[:user], password: lfs_credentials[:password] } + options[:basic_auth] = { username: lfs_credentials[:user], password: lfs_credentials[:password] } end end end def fetch_file(&block) - response = Gitlab::HTTP.get(lfs_sanitized_url, download_headers, &block) + response = Gitlab::HTTP.get(lfs_sanitized_url, download_options, &block) raise ResponseError, "Received error code #{response.code}" unless response.success? end |