Commit 3d013487 authored by Robert Schilling's avatar Robert Schilling

Grapify the CI::Runners API

parent a7a08738
module Ci module Ci
module API module API
# Runners API
class Runners < Grape::API class Runners < Grape::API
resource :runners do resource :runners do
# Delete runner desc 'Delete a runner'
# Parameters: params do
# token (required) - The unique token of runner requires :token, type: String, desc: 'The unique token of the runner'
# end
# Example Request:
# GET /runners/delete
delete "delete" do delete "delete" do
required_attributes! [:token]
authenticate_runner! authenticate_runner!
Ci::Runner.find_by_token(params[:token]).destroy Ci::Runner.find_by_token(params[:token]).destroy
end end
# Register a new runner desc 'Register a new runner' do
# success Entities::Runner
# Note: This is an "internal" API called when setting up end
# runners, so it is authenticated differently. params do
# requires :token, type: String, desc: 'The unique token of the runner'
# Parameters: optional :description, type: String, desc: 'The description of the runner'
# token (required) - The unique token of 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'
# Example Request: optional :locked, type: Boolean, desc: 'Lock this runner for this specific project'
# POST /runners/register end
post "register" do post "register" do
required_attributes! [:token] runner_params = declared(params, include_missing: false)
attributes = attributes_for_keys(
[:description, :tag_list, :run_untagged, :locked]
)
runner = runner =
if runner_registration_token_valid? if runner_registration_token_valid?
# Create shared runner. Requires admin access # Create shared runner. Requires admin access
Ci::Runner.create(attributes.merge(is_shared: true)) Ci::Runner.create(runner_params.merge(is_shared: true))
elsif project = Project.find_by(runners_token: params[:token]) elsif project = Project.find_by(runners_token: runner_params[:token])
# Create a specific runner for project. # Create a specific runner for project.
project.runners.create(attributes) project.runners.create(runner_params)
end end
return forbidden! unless runner return forbidden! unless runner
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment