From 28e324ae67821e19159d66a554065ae11fcfb42c Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 5 Jul 2016 22:58:38 +0800 Subject: Use Gitlab-Workhorse-Send-Data to send entry: Closes #19224, Closes #19128 Also requires this MR to work: https://gitlab.com/gitlab-org/gitlab-workhorse/merge_requests/53 --- app/controllers/projects/artifacts_controller.rb | 3 +-- app/helpers/workhorse_helper.rb | 6 ++++++ lib/gitlab/workhorse.rb | 12 ++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb index f11c8321464..c6363999670 100644 --- a/app/controllers/projects/artifacts_controller.rb +++ b/app/controllers/projects/artifacts_controller.rb @@ -23,8 +23,7 @@ class Projects::ArtifactsController < Projects::ApplicationController entry = build.artifacts_metadata_entry(params[:path]) if entry.exists? - render json: { archive: build.artifacts_file.path, - entry: Base64.encode64(entry.path) } + send_artifacts_entry(build, entry) else render json: {}, status: 404 end diff --git a/app/helpers/workhorse_helper.rb b/app/helpers/workhorse_helper.rb index 2bd0dbfd095..c582f16eb01 100644 --- a/app/helpers/workhorse_helper.rb +++ b/app/helpers/workhorse_helper.rb @@ -21,4 +21,10 @@ module WorkhorseHelper headers.store(*Gitlab::Workhorse.send_git_archive(repository, ref: ref, format: format)) head :ok end + + # Send an entry from artifacts through Workhorse + def send_artifacts_entry(build, entry) + headers.store(*Gitlab::Workhorse.send_artifacts_entry(build, entry)) + head :ok + end end diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb index ef1241f8600..ed1c5da0b3c 100644 --- a/lib/gitlab/workhorse.rb +++ b/lib/gitlab/workhorse.rb @@ -65,6 +65,18 @@ module Gitlab ] end + def send_artifacts_entry(build, entry) + params = { + 'Archive' => build.artifacts_file.path, + 'Entry' => Base64.encode64(entry.path) + } + + [ + SEND_DATA_HEADER, + "artifacts-entry:#{encode(params)}" + ] + end + protected def encode(hash) -- cgit v1.2.1 From 4b9f76cede975106e1e34af787e46720e3c3bb2e Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 6 Jul 2016 15:45:43 +0800 Subject: Fix one of the failing tests. Test against the headers --- features/steps/project/builds/artifacts.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/features/steps/project/builds/artifacts.rb b/features/steps/project/builds/artifacts.rb index 2876e8812e9..4bc74688132 100644 --- a/features/steps/project/builds/artifacts.rb +++ b/features/steps/project/builds/artifacts.rb @@ -68,10 +68,15 @@ class Spinach::Features::ProjectBuildsArtifacts < Spinach::FeatureSteps end step 'download of a file extracted from build artifacts should start' do - # this will be accelerated by Workhorse - response_json = JSON.parse(page.body, symbolize_names: true) - expect(response_json[:archive]).to end_with('build_artifacts.zip') - expect(response_json[:entry]).to eq Base64.encode64('ci_artifacts.txt') + send_data = response_headers[Gitlab::Workhorse::SEND_DATA_HEADER] + + expect(send_data).to start_with('artifacts-entry:') + + params = JSON.parse(Base64.urlsafe_decode64(send_data[/(?<=:)(.+)/])) + + expect(params.keys).to eq(['Archive', 'Entry']) + expect(params['Archive']).to end_with('build_artifacts.zip') + expect(params['Entry']).to eq(Base64.encode64('ci_artifacts.txt')) end step 'I click a first row within build artifacts table' do -- cgit v1.2.1 From 2b728ed3dabcced23370b39ce256a03cf30fe86d Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 11 Jul 2016 20:04:27 +0800 Subject: Just give regular 404, feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5094#note_12984211 --- app/controllers/projects/artifacts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb index c6363999670..7241949393b 100644 --- a/app/controllers/projects/artifacts_controller.rb +++ b/app/controllers/projects/artifacts_controller.rb @@ -25,7 +25,7 @@ class Projects::ArtifactsController < Projects::ApplicationController if entry.exists? send_artifacts_entry(build, entry) else - render json: {}, status: 404 + render_404 end end -- cgit v1.2.1 From 1bfc2ed633b2086b547727acc4aa0abaaea7731f Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 11 Jul 2016 20:06:35 +0800 Subject: Just remove the prefix, feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5094#note_12987385 --- features/steps/project/builds/artifacts.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/steps/project/builds/artifacts.rb b/features/steps/project/builds/artifacts.rb index 4bc74688132..b4a32ed2e38 100644 --- a/features/steps/project/builds/artifacts.rb +++ b/features/steps/project/builds/artifacts.rb @@ -72,7 +72,8 @@ class Spinach::Features::ProjectBuildsArtifacts < Spinach::FeatureSteps expect(send_data).to start_with('artifacts-entry:') - params = JSON.parse(Base64.urlsafe_decode64(send_data[/(?<=:)(.+)/])) + base64_params = send_data.sub(/\Aartifacts\-entry:/, '') + params = JSON.parse(Base64.urlsafe_decode64(base64_params)) expect(params.keys).to eq(['Archive', 'Entry']) expect(params['Archive']).to end_with('build_artifacts.zip') -- cgit v1.2.1