Merge branch 'backport-sticking-api-helper-changes' into 'master'

Backport API changes needed to fix sticking in EE

See merge request !10376
This commit is contained in:
Kamil Trzciński 2017-04-04 11:31:21 +00:00
commit 5efd67942c
5 changed files with 24 additions and 22 deletions

View file

@ -0,0 +1,4 @@
---
title: Backport API changes needed to fix sticking in EE
merge_request:
author:

View file

@ -50,10 +50,14 @@ module API
forbidden!('Job has been erased!') if job.erased? forbidden!('Job has been erased!') if job.erased?
end end
def authenticate_job!(job) def authenticate_job!
job = Ci::Build.find_by_id(params[:id])
validate_job!(job) do validate_job!(job) do
forbidden! unless job_token_valid?(job) forbidden! unless job_token_valid?(job)
end end
job
end end
def job_token_valid?(job) def job_token_valid?(job)

View file

@ -113,8 +113,7 @@ module API
optional :state, type: String, desc: %q(Job's status: success, failed) optional :state, type: String, desc: %q(Job's status: success, failed)
end end
put '/:id' do put '/:id' do
job = Ci::Build.find_by_id(params[:id]) job = authenticate_job!
authenticate_job!(job)
job.update_attributes(trace: params[:trace]) if params[:trace] job.update_attributes(trace: params[:trace]) if params[:trace]
@ -140,8 +139,7 @@ module API
optional :token, type: String, desc: %q(Job's authentication token) optional :token, type: String, desc: %q(Job's authentication token)
end end
patch '/:id/trace' do patch '/:id/trace' do
job = Ci::Build.find_by_id(params[:id]) job = authenticate_job!
authenticate_job!(job)
error!('400 Missing header Content-Range', 400) unless request.headers.has_key?('Content-Range') error!('400 Missing header Content-Range', 400) unless request.headers.has_key?('Content-Range')
content_range = request.headers['Content-Range'] content_range = request.headers['Content-Range']
@ -175,8 +173,7 @@ module API
require_gitlab_workhorse! require_gitlab_workhorse!
Gitlab::Workhorse.verify_api_request!(headers) Gitlab::Workhorse.verify_api_request!(headers)
job = Ci::Build.find_by_id(params[:id]) job = authenticate_job!
authenticate_job!(job)
forbidden!('Job is not running') unless job.running? forbidden!('Job is not running') unless job.running?
if params[:filesize] if params[:filesize]
@ -212,8 +209,7 @@ module API
not_allowed! unless Gitlab.config.artifacts.enabled not_allowed! unless Gitlab.config.artifacts.enabled
require_gitlab_workhorse! require_gitlab_workhorse!
job = Ci::Build.find_by_id(params[:id]) job = authenticate_job!
authenticate_job!(job)
forbidden!('Job is not running!') unless job.running? forbidden!('Job is not running!') unless job.running?
artifacts_upload_path = ArtifactUploader.artifacts_upload_path artifacts_upload_path = ArtifactUploader.artifacts_upload_path
@ -245,8 +241,7 @@ module API
optional :token, type: String, desc: %q(Job's authentication token) optional :token, type: String, desc: %q(Job's authentication token)
end end
get '/:id/artifacts' do get '/:id/artifacts' do
job = Ci::Build.find_by_id(params[:id]) job = authenticate_job!
authenticate_job!(job)
artifacts_file = job.artifacts_file artifacts_file = job.artifacts_file
unless artifacts_file.file_storage? unless artifacts_file.file_storage?

View file

@ -86,8 +86,7 @@ module Ci
# Example Request: # Example Request:
# PATCH /builds/:id/trace.txt # PATCH /builds/:id/trace.txt
patch ":id/trace.txt" do patch ":id/trace.txt" do
build = Ci::Build.find_by_id(params[:id]) build = authenticate_build!
authenticate_build!(build)
error!('400 Missing header Content-Range', 400) unless request.headers.has_key?('Content-Range') error!('400 Missing header Content-Range', 400) unless request.headers.has_key?('Content-Range')
content_range = request.headers['Content-Range'] content_range = request.headers['Content-Range']
@ -117,8 +116,7 @@ module Ci
require_gitlab_workhorse! require_gitlab_workhorse!
Gitlab::Workhorse.verify_api_request!(headers) Gitlab::Workhorse.verify_api_request!(headers)
not_allowed! unless Gitlab.config.artifacts.enabled not_allowed! unless Gitlab.config.artifacts.enabled
build = Ci::Build.find_by_id(params[:id]) build = authenticate_build!
authenticate_build!(build)
forbidden!('build is not running') unless build.running? forbidden!('build is not running') unless build.running?
if params[:filesize] if params[:filesize]
@ -154,8 +152,7 @@ module Ci
post ":id/artifacts" do post ":id/artifacts" do
require_gitlab_workhorse! require_gitlab_workhorse!
not_allowed! unless Gitlab.config.artifacts.enabled not_allowed! unless Gitlab.config.artifacts.enabled
build = Ci::Build.find_by_id(params[:id]) build = authenticate_build!
authenticate_build!(build)
forbidden!('Build is not running!') unless build.running? forbidden!('Build is not running!') unless build.running?
artifacts_upload_path = ArtifactUploader.artifacts_upload_path artifacts_upload_path = ArtifactUploader.artifacts_upload_path
@ -189,8 +186,7 @@ module Ci
# Example Request: # Example Request:
# GET /builds/:id/artifacts # GET /builds/:id/artifacts
get ":id/artifacts" do get ":id/artifacts" do
build = Ci::Build.find_by_id(params[:id]) build = authenticate_build!
authenticate_build!(build)
artifacts_file = build.artifacts_file artifacts_file = build.artifacts_file
unless artifacts_file.file_storage? unless artifacts_file.file_storage?
@ -214,8 +210,7 @@ module Ci
# Example Request: # Example Request:
# DELETE /builds/:id/artifacts # DELETE /builds/:id/artifacts
delete ":id/artifacts" do delete ":id/artifacts" do
build = Ci::Build.find_by_id(params[:id]) build = authenticate_build!
authenticate_build!(build)
status(200) status(200)
build.erase_artifacts! build.erase_artifacts!

View file

@ -13,10 +13,14 @@ module Ci
forbidden! unless current_runner forbidden! unless current_runner
end end
def authenticate_build!(build) def authenticate_build!
build = Ci::Build.find_by_id(params[:id])
validate_build!(build) do validate_build!(build) do
forbidden! unless build_token_valid?(build) forbidden! unless build_token_valid?(build)
end end
build
end end
def validate_build!(build) def validate_build!(build)