diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-02-06 15:39:20 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-02-28 20:58:56 +0100 |
commit | b14c484bb1d174c7c355de2258be1a4414b2cf78 (patch) | |
tree | e7cf84f28c964580b74f791d235987948f3cc4a8 /lib | |
parent | a7dae52e9d27adde427ef8aa066c0761071a3cd9 (diff) | |
download | gitlab-ce-b14c484bb1d174c7c355de2258be1a4414b2cf78.tar.gz |
Merge branch 'use-send-url-for-incompatible-runners' into 'master'
Support SendURL for performing indirect download of artifacts if clients does…
See merge request gitlab-org/gitlab-ee!4401
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/helpers.rb | 8 | ||||
-rw-r--r-- | lib/api/runner.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/workhorse.rb | 12 |
3 files changed, 20 insertions, 3 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index cc81e4d3595..d4ca945873c 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -418,13 +418,17 @@ module API end end - def present_artifacts!(artifacts_file) + def present_artifacts!(artifacts_file, direct_download: true) return not_found! unless artifacts_file.exists? if artifacts_file.file_storage? present_file!(artifacts_file.path, artifacts_file.filename) - else + elsif direct_download redirect(artifacts_file.url) + else + header(*Gitlab::Workhorse.send_url(artifacts_file.url)) + status :ok + body end end diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 1f80646a2ea..e6e85d41806 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -244,11 +244,12 @@ module API params do requires :id, type: Integer, desc: %q(Job's ID) optional :token, type: String, desc: %q(Job's authentication token) + optional :direct_download, default: false, type: Boolean, desc: %q(Perform direct download from remote storage instead of proxying artifacts) end get '/:id/artifacts' do job = authenticate_job! - present_artifacts!(job.artifacts_file) + present_artifacts!(job.artifacts_file, direct_download: params[:direct_download]) end end end diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb index dfe8acd4833..990a6b1d80d 100644 --- a/lib/gitlab/workhorse.rb +++ b/lib/gitlab/workhorse.rb @@ -151,6 +151,18 @@ module Gitlab ] end + def send_url(url, allow_redirects: false) + params = { + 'URL' => url, + 'AllowRedirects' => allow_redirects + } + + [ + SEND_DATA_HEADER, + "send-url:#{encode(params)}" + ] + end + def terminal_websocket(terminal) details = { 'Terminal' => { |