2015-08-25 21:42:46 -04:00
|
|
|
module Ci
|
|
|
|
module API
|
|
|
|
class Runners < Grape::API
|
|
|
|
resource :runners do
|
2017-02-22 05:03:04 -05:00
|
|
|
desc 'Delete a runner'
|
|
|
|
params do
|
|
|
|
requires :token, type: String, desc: 'The unique token of the runner'
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
delete "delete" do
|
|
|
|
authenticate_runner!
|
2017-02-24 04:24:14 -05:00
|
|
|
|
|
|
|
status(200)
|
2015-08-25 21:42:46 -04:00
|
|
|
Ci::Runner.find_by_token(params[:token]).destroy
|
|
|
|
end
|
|
|
|
|
2017-02-22 05:03:04 -05:00
|
|
|
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-08-25 21:42:46 -04:00
|
|
|
post "register" do
|
2017-02-22 05:03:04 -05:00
|
|
|
runner_params = declared(params, include_missing: false)
|
2016-05-06 08:06:57 -04:00
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
runner =
|
2015-12-10 07:50:00 -05:00
|
|
|
if runner_registration_token_valid?
|
2015-08-25 21:42:46 -04:00
|
|
|
# Create shared runner. Requires admin access
|
2017-02-22 05:03:04 -05:00
|
|
|
Ci::Runner.create(runner_params.merge(is_shared: true))
|
|
|
|
elsif project = Project.find_by(runners_token: runner_params[:token])
|
2015-08-25 21:42:46 -04:00
|
|
|
# Create a specific runner for project.
|
2017-02-22 05:03:04 -05:00
|
|
|
project.runners.create(runner_params)
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
return forbidden! unless runner
|
|
|
|
|
|
|
|
if runner.id
|
2016-01-26 13:25:48 -05:00
|
|
|
runner.update(get_runner_version_from_params)
|
2015-08-25 21:42:46 -04:00
|
|
|
present runner, with: Entities::Runner
|
|
|
|
else
|
|
|
|
not_found!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|