From 3d26a8d0b62f70e02917f7601bc2032fb3aed7e6 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Wed, 15 Feb 2017 18:08:29 +0100 Subject: Add jobs requesting API --- lib/api/entities.rb | 38 ++++++++++++++++++++++++++++++++++++++ lib/api/helpers/runner.rb | 28 ++++++++++++++++++++++++++++ lib/api/runner.rb | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 9dccaff369e..cb3b409b8d0 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -697,5 +697,43 @@ module API expose :id, :message, :starts_at, :ends_at, :color, :font expose :active?, as: :active end + + class ArtifactFile < Grape::Entity + expose :filename, :size + end + + class JobCredentials < Grape::Entity + expose :type, :url, :username, :password + end + + class JobResponse < Grape::Entity + expose :id, :ref, :tag, :sha, :status + expose :name, :token, :stage + expose :project_id + expose :project_name + expose :artifacts_file, using: ArtifactFile, if: ->(build, _) { build.artifacts? } + end + + class RequestJobResponse < JobResponse + expose :commands + expose :repo_url + expose :before_sha + expose :allow_git_fetch + expose :token + expose :artifacts_expire_at, if: ->(build, _) { build.artifacts? } + + expose :options do |model| + model.options + end + + expose :timeout do |model| + model.timeout + end + + expose :variables + expose :depends_on_builds, using: JobResponse + + expose :credentials, using: JobCredentials + end end end diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index 119ca81b883..8db0fc117c6 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -1,6 +1,8 @@ module API module Helpers module Runner + UPDATE_RUNNER_EVERY = 10 * 60 + def runner_registration_token_valid? ActiveSupport::SecurityUtils.variable_size_secure_compare(params[:token], current_application_settings.runners_registration_token) @@ -18,6 +20,32 @@ module API def current_runner @runner ||= ::Ci::Runner.find_by_token(params[:token].to_s) end + + def update_runner_info + return unless update_runner? + + current_runner.contacted_at = Time.now + current_runner.assign_attributes(get_runner_version_from_params) + current_runner.save if current_runner.changed? + end + + def update_runner? + # Use a random threshold to prevent beating DB updates. + # It generates a distribution between [40m, 80m]. + # + contacted_at_max_age = UPDATE_RUNNER_EVERY + Random.rand(UPDATE_RUNNER_EVERY) + + current_runner.contacted_at.nil? || + (Time.now - current_runner.contacted_at) >= contacted_at_max_age + end + + def build_not_found! + if headers['User-Agent'].to_s.match(/gitlab(-ci-multi)?-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /) + no_content! + else + not_found! + end + end end end end diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 47858f1866b..2e7b96e5169 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -48,5 +48,44 @@ module API Ci::Runner.find_by_token(params[:token]).destroy end end + + resource :jobs do + desc 'Request a job' do + success Entities::RequestJobResponse + end + params do + requires :token, type: String, desc: %q(Runner's authentication token) + end + post '/request' do + authenticate_runner! + not_found! unless current_runner.active? + update_runner_info + + if current_runner.is_runner_queue_value_latest?(params[:last_update]) + header 'X-GitLab-Last-Update', params[:last_update] + Gitlab::Metrics.add_event(:build_not_found_cached) + return build_not_found! + end + + new_update = current_runner.ensure_runner_queue_value + result = ::Ci::RegisterBuildService.new(current_runner).execute + + if result.valid? + if result.build + Gitlab::Metrics.add_event(:build_found, + project: result.build.project.path_with_namespace) + present result.build, with: Entities::RequestJobResponse + else + Gitlab::Metrics.add_event(:build_not_found) + header 'X-GitLab-Last-Update', new_update + build_not_found! + end + else + # We received build that is invalid due to concurrency conflict + Gitlab::Metrics.add_event(:build_invalid) + conflict! + end + end + end end end -- cgit v1.2.1 From 3eafffcef0f8932bab4e06b465f9b63327e87942 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 16 Feb 2017 01:05:44 +0100 Subject: Refactor JobRequest response structure --- lib/api/entities.rb | 94 ++++++++++++++++++++++++++++++++++++++--------------- lib/api/runner.rb | 6 ++-- 2 files changed, 70 insertions(+), 30 deletions(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index cb3b409b8d0..7e07154600a 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -698,42 +698,82 @@ module API expose :active?, as: :active end - class ArtifactFile < Grape::Entity - expose :filename, :size - end + module JobRequest + class JobInfo < Grape::Entity + expose :name, :stage + expose :project_id, :project_name + end + + class GitInfo < Grape::Entity + expose :repo_url, :ref, :sha, :before_sha + expose :ref_type do |model| + if model.tag + 'tag' + else + 'branch' + end + end + end - class JobCredentials < Grape::Entity - expose :type, :url, :username, :password - end + class RunnerInfo < Grape::Entity + expose :timeout + end - class JobResponse < Grape::Entity - expose :id, :ref, :tag, :sha, :status - expose :name, :token, :stage - expose :project_id - expose :project_name - expose :artifacts_file, using: ArtifactFile, if: ->(build, _) { build.artifacts? } - end + class Step < Grape::Entity + expose :name, :script, :timeout, :condition, :result + end - class RequestJobResponse < JobResponse - expose :commands - expose :repo_url - expose :before_sha - expose :allow_git_fetch - expose :token - expose :artifacts_expire_at, if: ->(build, _) { build.artifacts? } + class Image < Grape::Entity + expose :name + end - expose :options do |model| - model.options + class Artifacts < Grape::Entity + expose :name, :untracked, :paths, :when, :expire_in end - expose :timeout do |model| - model.timeout + class Cache < Grape::Entity + expose :key, :untracked, :paths end - expose :variables - expose :depends_on_builds, using: JobResponse + class Credentials < Grape::Entity + expose :type, :url, :username, :password + end - expose :credentials, using: JobCredentials + class ArtifactFile < Grape::Entity + expose :filename, :size + end + + class Dependency < Grape::Entity + expose :id, :name + expose :artifacts_file, using: ArtifactFile, if: ->(job, _) { job.artifacts? } + end + + class Response < Grape::Entity + expose :id + expose :token + expose :allow_git_fetch + + expose :job_info, using: JobInfo do |model| + model + end + + expose :git_info, using: GitInfo do |model| + model + end + + expose :runner_info, using: RunnerInfo do |model| + model + end + + expose :variables + expose :steps, using: Step + expose :image, using: Image + expose :services, using: Image + expose :artifacts, using: Artifacts + expose :cache, using: Cache + expose :credentials, using: Credentials + expose :depends_on_builds, as: :dependencies, using: Dependency + end end end end diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 2e7b96e5169..8372b794739 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -51,7 +51,7 @@ module API resource :jobs do desc 'Request a job' do - success Entities::RequestJobResponse + success Entities::JobRequest::Response end params do requires :token, type: String, desc: %q(Runner's authentication token) @@ -68,13 +68,13 @@ module API end new_update = current_runner.ensure_runner_queue_value - result = ::Ci::RegisterBuildService.new(current_runner).execute + result = ::Ci::RegisterJobService.new(current_runner).execute if result.valid? if result.build Gitlab::Metrics.add_event(:build_found, project: result.build.project.path_with_namespace) - present result.build, with: Entities::RequestJobResponse + present result.build, with: Entities::JobRequest::Response else Gitlab::Metrics.add_event(:build_not_found) header 'X-GitLab-Last-Update', new_update -- cgit v1.2.1 From bbf5bb7070d5b7828c3e7f7301b7f645fd39b51f Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 16 Feb 2017 01:38:53 +0100 Subject: Fix rubocop offenses --- lib/api/helpers/runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index 8db0fc117c6..8204adbcfe5 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -36,7 +36,7 @@ module API contacted_at_max_age = UPDATE_RUNNER_EVERY + Random.rand(UPDATE_RUNNER_EVERY) current_runner.contacted_at.nil? || - (Time.now - current_runner.contacted_at) >= contacted_at_max_age + (Time.now - current_runner.contacted_at) >= contacted_at_max_age end def build_not_found! -- cgit v1.2.1 From 65564598d90b24766fc4eae79a2203daf77c2ce0 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Mon, 27 Feb 2017 14:21:06 +0100 Subject: Add missing param description for POST /api/v4/jobs/request --- lib/api/runner.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/api') diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 8372b794739..ada1073c8dc 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -55,6 +55,8 @@ module API end params do requires :token, type: String, desc: %q(Runner's authentication token) + optional :last_update, type: String, desc: %q(Runner's queue last_update token) + optional :info, type: Hash, desc: %q(Runner's metadata) end post '/request' do authenticate_runner! -- cgit v1.2.1 From fb8210ad19dcf012ffd1a99a649846d82870b8af Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Mon, 27 Feb 2017 16:05:44 +0100 Subject: Update step data naming --- lib/api/entities.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 7e07154600a..f961102b910 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -720,7 +720,7 @@ module API end class Step < Grape::Entity - expose :name, :script, :timeout, :condition, :result + expose :name, :script, :timeout, :when, :allow_failure end class Image < Grape::Entity -- cgit v1.2.1 From d5f7e5421157dbd1be134247dfec318c0db546a8 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Tue, 28 Feb 2017 12:52:08 +0100 Subject: Add job update API --- lib/api/helpers/runner.rb | 11 ++++++++++- lib/api/runner.rb | 30 ++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) (limited to 'lib/api') diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index 8204adbcfe5..15eb6b932ed 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -39,13 +39,22 @@ module API (Time.now - current_runner.contacted_at) >= contacted_at_max_age end - def build_not_found! + def job_not_found! if headers['User-Agent'].to_s.match(/gitlab(-ci-multi)?-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /) no_content! else not_found! end end + + def validate_job!(job) + not_found! unless job + + yield if block_given? + + forbidden!('Project has been deleted!') unless job.project + forbidden!('Job has been erased!') if job.erased? + end end end end diff --git a/lib/api/runner.rb b/lib/api/runner.rb index ada1073c8dc..b57fbdabab9 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -66,7 +66,7 @@ module API if current_runner.is_runner_queue_value_latest?(params[:last_update]) header 'X-GitLab-Last-Update', params[:last_update] Gitlab::Metrics.add_event(:build_not_found_cached) - return build_not_found! + return job_not_found! end new_update = current_runner.ensure_runner_queue_value @@ -80,7 +80,7 @@ module API else Gitlab::Metrics.add_event(:build_not_found) header 'X-GitLab-Last-Update', new_update - build_not_found! + job_not_found! end else # We received build that is invalid due to concurrency conflict @@ -88,6 +88,32 @@ module API conflict! end end + + desc 'Updates a job' do + http_codes [[200, 'Job was updated'], [403, 'Forbidden']] + end + params do + requires :token, type: String, desc: %q(Job's authentication token) + requires :id, type: Fixnum, desc: %q(Job's ID) + optional :trace, type: String, desc: %q(Job's full trace) + optional :state, type: String, desc: %q(Job's status: success, failed) + end + put '/:id' do + job = Ci::Build.find_by_id(params[:id]) + authenticate_job!(job) + + job.update_attributes(trace: params[:trace]) if params[:trace] + + Gitlab::Metrics.add_event(:update_build, + project: job.project.path_with_namespace) + + case params[:state].to_s + when 'success' + job.success + when 'failed' + job.drop + end + end end end end -- cgit v1.2.1 From 7e46db0f5a5b6aa84ac653fa4826b70bf50d6909 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Tue, 28 Feb 2017 13:29:52 +0100 Subject: Add job patch trace API --- lib/api/helpers/runner.rb | 13 +++++++++++++ lib/api/runner.rb | 32 +++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index 15eb6b932ed..e71895c091e 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -1,6 +1,8 @@ module API module Helpers module Runner + JOB_TOKEN_HEADER = 'HTTP_JOB_TOKEN' + JOB_TOKEN_PARAM = :token UPDATE_RUNNER_EVERY = 10 * 60 def runner_registration_token_valid? @@ -55,6 +57,17 @@ module API forbidden!('Project has been deleted!') unless job.project forbidden!('Job has been erased!') if job.erased? end + + def authenticate_job!(job) + validate_job!(job) do + forbidden! unless job_token_valid?(job) + end + end + + def job_token_valid?(job) + token = (params[JOB_TOKEN_PARAM] || env[JOB_TOKEN_HEADER]).to_s + token && job.valid_token?(token) + end end end end diff --git a/lib/api/runner.rb b/lib/api/runner.rb index b57fbdabab9..2b636847dba 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -93,7 +93,7 @@ module API http_codes [[200, 'Job was updated'], [403, 'Forbidden']] end params do - requires :token, type: String, desc: %q(Job's authentication token) + requires :token, type: String, desc: %q(Runners's authentication token) requires :id, type: Fixnum, desc: %q(Job's ID) optional :trace, type: String, desc: %q(Job's full trace) optional :state, type: String, desc: %q(Job's status: success, failed) @@ -114,6 +114,36 @@ module API job.drop end end + + desc 'Appends a patch to the job.trace' do + http_codes [[202, 'Trace was patched'], + [400, 'Missing Content-Range header'], + [403, 'Forbidden'], + [416, 'Range not satisfiable']] + end + params do + requires :id, type: Fixnum, desc: %q(Job's ID) + optional :token, type: String, desc: %q(Job's authentication token) + end + patch '/:id/trace' do + job = Ci::Build.find_by_id(params[:id]) + authenticate_job!(job) + + error!('400 Missing header Content-Range', 400) unless request.headers.has_key?('Content-Range') + content_range = request.headers['Content-Range'] + content_range = content_range.split('-') + + current_length = job.trace_length + unless current_length == content_range[0].to_i + return error!('416 Range Not Satisfiable', 416, { 'Range' => "0-#{current_length}" }) + end + + job.append_trace(request.body.read, content_range[0].to_i) + + status 202 + header 'Job-Status', job.status + header 'Range', "0-#{job.trace_length}" + end end end end -- cgit v1.2.1 From 2a7f555caf8588ad78f054f29e740a2a4a30deb3 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Tue, 28 Feb 2017 14:27:25 +0100 Subject: Add artifacts uploading authorize API --- lib/api/helpers/runner.rb | 4 ++++ lib/api/runner.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'lib/api') diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index e71895c091e..97255cc8c81 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -68,6 +68,10 @@ module API token = (params[JOB_TOKEN_PARAM] || env[JOB_TOKEN_HEADER]).to_s token && job.valid_token?(token) end + + def max_artifacts_size + current_application_settings.max_artifacts_size.megabytes.to_i + end end end end diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 2b636847dba..54105988f36 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -144,6 +144,36 @@ module API header 'Job-Status', job.status header 'Range', "0-#{job.trace_length}" end + + desc 'Authorize artifacts uploading for job' do + http_codes [[200, 'Upload allowed'], + [403, 'Forbidden'], + [405, 'Artifacts support not enabled'], + [413, 'File too large']] + end + params do + requires :id, type: Fixnum, desc: %q(Job's ID) + optional :token, type: String, desc: %q(Job's authentication token) + optional :filesize, type: Fixnum, desc: %q(ARtifacts filesize) + end + post '/:id/artifacts/authorize' do + not_allowed! unless Gitlab.config.artifacts.enabled + require_gitlab_workhorse! + Gitlab::Workhorse.verify_api_request!(headers) + + job = Ci::Build.find_by_id(params[:id]) + authenticate_job!(job) + forbidden!('Job is not running') unless job.running? + + if params[:filesize] + file_size = params[:filesize].to_i + file_to_large! unless file_size < max_artifacts_size + end + + status 200 + content_type Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE + Gitlab::Workhorse.artifact_upload_ok + end end end end -- cgit v1.2.1 From c2eb54760d74cb901d251e8e0af5e9d0db314755 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Tue, 28 Feb 2017 17:36:17 +0100 Subject: Add artifacts uploading API --- lib/api/runner.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'lib/api') diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 54105988f36..01c7740b614 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -174,6 +174,53 @@ module API content_type Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE Gitlab::Workhorse.artifact_upload_ok end + + desc 'Upload artifacts for job' do + http_codes [[201, 'Artifact uploaded'], + [400, 'Bad request'], + [403, 'Forbidden'], + [405, 'Artifacts support not enabled'], + [413, 'File too large']] + end + params do + requires :id, type: Fixnum, desc: %q(Job's ID) + optional :token, type: String, desc: %q(Job's authentication token) + optional :expire_in, type: String, desc: %q(Specify when artifacts should expire) + optional 'file', type: File, desc: %q(Artifact's file) + optional 'file.path', type: String, desc: %q(path to locally stored body (generated by Workhorse)) + optional 'file.name', type: String, desc: %q(real filename as send in Content-Disposition (generated by Workhorse)) + optional 'file.type', type: String, desc: %q(real content type as send in Content-Type (generated by Workhorse)) + optional 'metadata.path', type: String, desc: %q(path to locally stored body (generated by Workhorse)) + optional 'metadata.name', type: String, desc: %q(filename (generated by Workhorse)) + end + post '/:id/artifacts' do + not_allowed! unless Gitlab.config.artifacts.enabled + require_gitlab_workhorse! + + job = Ci::Build.find_by_id(params[:id]) + authenticate_job!(job) + forbidden!('Job is not running!') unless job.running? + + artifacts_upload_path = ArtifactUploader.artifacts_upload_path + artifacts = uploaded_file(:file, artifacts_upload_path) + metadata = uploaded_file(:metadata, artifacts_upload_path) + + bad_request!('Missing artifacts file!') unless artifacts + file_to_large! unless artifacts.size < max_artifacts_size + + job.artifacts_file = artifacts + job.artifacts_metadata = metadata + job.artifacts_expire_in = params['expire_in'] || + Gitlab::CurrentSettings + .current_application_settings + .default_artifacts_expire_in + + if job.save + present job, with: Entities::JobRequest::Response + else + render_validation_error!(job) + end + end end end end -- cgit v1.2.1 From f7d352341eb4a0eea98889275cbbeb46049d21a2 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Tue, 28 Feb 2017 17:55:56 +0100 Subject: Add artifacts downloading API --- lib/api/runner.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/api') diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 01c7740b614..4cbc2fb08c2 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -221,6 +221,31 @@ module API render_validation_error!(job) end end + + desc 'Download the artifacts file for job' do + http_codes [[200, 'Upload allowed'], + [403, 'Forbidden'], + [404, 'Artifact not found']] + end + params do + requires :id, type: Fixnum, desc: %q(Job's ID) + optional :token, type: String, desc: %q(Job's authentication token) + end + get '/:id/artifacts' do + job = Ci::Build.find_by_id(params[:id]) + authenticate_job!(job) + + artifacts_file = job.artifacts_file + unless artifacts_file.file_storage? + return redirect_to job.artifacts_file.url + end + + unless artifacts_file.exists? + not_found! + end + + present_file!(artifacts_file.path, artifacts_file.filename) + end end end end -- cgit v1.2.1 From 1bbf2c2cd16140aa95bbf93368209b16795172bd Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Tue, 28 Feb 2017 20:25:58 +0100 Subject: Fix rubocop offenses --- lib/api/helpers/runner.rb | 4 ++-- lib/api/runner.rb | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'lib/api') diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index 97255cc8c81..ec2bcaed929 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -1,7 +1,7 @@ module API module Helpers module Runner - JOB_TOKEN_HEADER = 'HTTP_JOB_TOKEN' + JOB_TOKEN_HEADER = 'HTTP_JOB_TOKEN'.freeze JOB_TOKEN_PARAM = :token UPDATE_RUNNER_EVERY = 10 * 60 @@ -42,7 +42,7 @@ module API end def job_not_found! - if headers['User-Agent'].to_s.match(/gitlab(-ci-multi)?-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /) + if headers['User-Agent'].to_s =~ /gitlab(-ci-multi)?-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? / no_content! else not_found! diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 4cbc2fb08c2..23db32c9b1f 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -94,7 +94,7 @@ module API end params do requires :token, type: String, desc: %q(Runners's authentication token) - requires :id, type: Fixnum, desc: %q(Job's ID) + requires :id, type: Integer, desc: %q(Job's ID) optional :trace, type: String, desc: %q(Job's full trace) optional :state, type: String, desc: %q(Job's status: success, failed) end @@ -122,7 +122,7 @@ module API [416, 'Range not satisfiable']] end params do - requires :id, type: Fixnum, desc: %q(Job's ID) + requires :id, type: Integer, desc: %q(Job's ID) optional :token, type: String, desc: %q(Job's authentication token) end patch '/:id/trace' do @@ -152,9 +152,9 @@ module API [413, 'File too large']] end params do - requires :id, type: Fixnum, desc: %q(Job's ID) + requires :id, type: Integer, desc: %q(Job's ID) optional :token, type: String, desc: %q(Job's authentication token) - optional :filesize, type: Fixnum, desc: %q(ARtifacts filesize) + optional :filesize, type: Integer, desc: %q(Artifacts filesize) end post '/:id/artifacts/authorize' do not_allowed! unless Gitlab.config.artifacts.enabled @@ -183,7 +183,7 @@ module API [413, 'File too large']] end params do - requires :id, type: Fixnum, desc: %q(Job's ID) + requires :id, type: Integer, desc: %q(Job's ID) optional :token, type: String, desc: %q(Job's authentication token) optional :expire_in, type: String, desc: %q(Specify when artifacts should expire) optional 'file', type: File, desc: %q(Artifact's file) @@ -211,9 +211,7 @@ module API job.artifacts_file = artifacts job.artifacts_metadata = metadata job.artifacts_expire_in = params['expire_in'] || - Gitlab::CurrentSettings - .current_application_settings - .default_artifacts_expire_in + Gitlab::CurrentSettings.current_application_settings.default_artifacts_expire_in if job.save present job, with: Entities::JobRequest::Response @@ -228,7 +226,7 @@ module API [404, 'Artifact not found']] end params do - requires :id, type: Fixnum, desc: %q(Job's ID) + requires :id, type: Integer, desc: %q(Job's ID) optional :token, type: String, desc: %q(Job's authentication token) end get '/:id/artifacts' do -- cgit v1.2.1 From 5c1aa5fb65ec7474956e6972e40b04b3a967c338 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 2 Mar 2017 17:44:15 +0100 Subject: Add some fixes and refactoring after review --- lib/api/runner.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 23db32c9b1f..caa330c7234 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -176,6 +176,7 @@ module API end desc 'Upload artifacts for job' do + success Entities::JobRequest::Response http_codes [[201, 'Artifact uploaded'], [400, 'Bad request'], [403, 'Forbidden'], @@ -186,7 +187,7 @@ module API requires :id, type: Integer, desc: %q(Job's ID) optional :token, type: String, desc: %q(Job's authentication token) optional :expire_in, type: String, desc: %q(Specify when artifacts should expire) - optional 'file', type: File, desc: %q(Artifact's file) + optional :file, type: File, desc: %q(Artifact's file) optional 'file.path', type: String, desc: %q(path to locally stored body (generated by Workhorse)) optional 'file.name', type: String, desc: %q(real filename as send in Content-Disposition (generated by Workhorse)) optional 'file.type', type: String, desc: %q(real content type as send in Content-Type (generated by Workhorse)) -- cgit v1.2.1 From 32b09b8847955052765895063297181835c45b8c Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Tue, 7 Mar 2017 12:30:34 +0100 Subject: Add minor refactoring --- lib/api/runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/runner.rb b/lib/api/runner.rb index caa330c7234..c700d2ef4a1 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -115,7 +115,7 @@ module API end end - desc 'Appends a patch to the job.trace' do + desc 'Appends a patch to the job trace' do http_codes [[202, 'Trace was patched'], [400, 'Missing Content-Range header'], [403, 'Forbidden'], -- cgit v1.2.1