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

57 lines
1.6 KiB
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
module Ci
module API
# Runners API
class Runners < Grape::API
resource :runners do
# Delete runner
# Parameters:
# token (required) - The unique token of runner
#
# Example Request:
# GET /runners/delete
delete "delete" do
required_attributes! [:token]
authenticate_runner!
Ci::Runner.find_by_token(params[:token]).destroy
end
# Register a new runner
#
# Note: This is an "internal" API called when setting up
# runners, so it is authenticated differently.
#
# Parameters:
# token (required) - The unique token of runner
#
# Example Request:
# POST /runners/register
post "register" do
required_attributes! [:token]
2016-06-22 15:30:34 +05:30
attributes = attributes_for_keys(
[:description, :tag_list, :run_untagged, :locked]
)
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
2016-06-02 11:05:42 +05:30
Ci::Runner.create(attributes.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.
2016-06-02 11:05:42 +05:30
project.runners.create(attributes)
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