debian-mirror-gitlab/lib/ci/api/runners.rb

51 lines
1.7 KiB
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
module Ci
module API
class Runners < Grape::API
resource :runners do
2017-08-17 22:00:37 +05:30
desc 'Delete a runner'
params do
requires :token, type: String, desc: 'The unique token of the runner'
end
2015-09-25 12:07:36 +05:30
delete "delete" do
authenticate_runner!
2017-08-17 22:00:37 +05:30
status(200)
2015-09-25 12:07:36 +05:30
Ci::Runner.find_by_token(params[:token]).destroy
end
2017-08-17 22:00:37 +05:30
desc 'Register a new runner' do
success Entities::Runner
end
params do
requires :token, type: String, desc: 'The unique token of the runner'
optional :description, type: String, desc: 'The description of the runner'
optional :tag_list, type: Array[String], desc: 'A list of tags the runner should run for'
optional :run_untagged, type: Boolean, desc: 'Flag if the runner should execute untagged jobs'
optional :locked, type: Boolean, desc: 'Lock this runner for this specific project'
end
2015-09-25 12:07:36 +05:30
post "register" do
2017-08-17 22:00:37 +05:30
runner_params = declared(params, include_missing: false).except(:token)
2016-06-02 11:05:42 +05:30
2015-09-25 12:07:36 +05:30
runner =
2015-12-23 02:04:40 +05:30
if runner_registration_token_valid?
2015-09-25 12:07:36 +05:30
# Create shared runner. Requires admin access
2017-08-17 22:00:37 +05:30
Ci::Runner.create(runner_params.merge(is_shared: true))
2015-12-23 02:04:40 +05:30
elsif project = Project.find_by(runners_token: params[:token])
2015-09-25 12:07:36 +05:30
# Create a specific runner for project.
2017-08-17 22:00:37 +05:30
project.runners.create(runner_params)
2015-09-25 12:07:36 +05:30
end
return forbidden! unless runner
if runner.id
2016-02-05 20:25:01 +05:30
runner.update(get_runner_version_from_params)
2015-09-25 12:07:36 +05:30
present runner, with: Entities::Runner
else
not_found!
end
end
end
end
end
end