BigW Consortium Gitlab

runners.rb 1.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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]

31
          attributes = { description: params[:description],
32 33 34
                         tag_list: params[:tag_list] }

          unless params[:run_untagged].nil?
35
            attributes[:run_untagged] = params[:run_untagged]
36
          end
37

38
          runner =
39
            if runner_registration_token_valid?
40
              # Create shared runner. Requires admin access
41
              Ci::Runner.create(attributes.merge(is_shared: true))
Kamil Trzcinski committed
42
            elsif project = Project.find_by(runners_token: params[:token])
43
              # Create a specific runner for project.
44
              project.runners.create(attributes)
45 46 47 48 49
            end

          return forbidden! unless runner

          if runner.id
50
            runner.update(get_runner_version_from_params)
51 52 53 54 55 56 57 58 59
            present runner, with: Entities::Runner
          else
            not_found!
          end
        end
      end
    end
  end
end