Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_runners.rb « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: edbd0214bb81187d965f76f18c00c274c81fa377 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# frozen_string_literal: true

module API
  class UserRunners < ::API::Base
    include APIGuard

    resource :user do
      before do
        authenticate!
      end

      allow_access_with_scope :create_runner, if: ->(request) { request.post? }

      desc 'Create a runner owned by currently authenticated user' do
        detail 'Create a new runner'
        success Entities::Ci::RunnerRegistrationDetails
        failure [[400, 'Bad Request'], [403, 'Forbidden']]
        tags %w[user runners]
      end
      params do
        requires :runner_type, type: String, values: ::Ci::Runner.runner_types.keys,
          desc: %q(Specifies the scope of the runner)
        given runner_type: ->(runner_type) { runner_type == 'group_type' } do
          requires :group_id, type: Integer,
            desc: 'The ID of the group that the runner is created in',
            documentation: { example: 1 }
        end
        given runner_type: ->(runner_type) { runner_type == 'project_type' } do
          requires :project_id, type: Integer,
            desc: 'The ID of the project that the runner is created in',
            documentation: { example: 1 }
        end
        optional :description, type: String, desc: %q(Description of the runner)
        optional :maintenance_note, type: String,
          desc: %q(Free-form maintenance notes for the runner (1024 characters))
        optional :paused, type: Boolean, desc: 'Specifies if the runner should ignore new jobs (defaults to false)'
        optional :locked, type: Boolean,
          desc: 'Specifies if the runner should be locked for the current project (defaults to false)'
        optional :access_level, type: String, values: ::Ci::Runner.access_levels.keys,
          desc: 'The access level of the runner'
        optional :run_untagged, type: Boolean,
          desc: 'Specifies if the runner should handle untagged jobs  (defaults to true)'
        optional :tag_list, type: Array[String], coerce_with: ::API::Validations::Types::CommaSeparatedToArray.coerce,
          desc: %q(A list of runner tags)
        optional :maximum_timeout, type: Integer,
          desc: 'Maximum timeout that limits the amount of time (in seconds) that runners can run jobs'
      end
      post 'runners', urgency: :low, feature_category: :runner_fleet do
        attributes = attributes_for_keys(
          %i[runner_type group_id project_id description maintenance_note paused locked run_untagged tag_list
            access_level maximum_timeout]
        )

        case attributes[:runner_type]
        when 'group_type'
          attributes[:scope] = ::Group.find_by_id(attributes.delete(:group_id))
        when 'project_type'
          attributes[:scope] = ::Project.find_by_id(attributes.delete(:project_id))
        end

        result = ::Ci::Runners::CreateRunnerService.new(user: current_user, params: attributes).execute
        if result.error?
          message = result.errors.to_sentence
          forbidden!(message) if result.reason == :forbidden
          bad_request!(message)
        end

        present result.payload[:runner], with: Entities::Ci::RunnerRegistrationDetails
      end
    end
  end
end