summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2017-02-28 14:27:25 +0100
committerTomasz Maczukin <tomasz@maczukin.pl>2017-03-02 17:45:46 +0100
commit2a7f555caf8588ad78f054f29e740a2a4a30deb3 (patch)
treeb929b08b1adc7fdb9f8666a2f980495a8a32a293 /lib
parent7e46db0f5a5b6aa84ac653fa4826b70bf50d6909 (diff)
downloadgitlab-ce-2a7f555caf8588ad78f054f29e740a2a4a30deb3.tar.gz
Add artifacts uploading authorize API
Diffstat (limited to 'lib')
-rw-r--r--lib/api/helpers/runner.rb4
-rw-r--r--lib/api/runner.rb30
2 files changed, 34 insertions, 0 deletions
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