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

runner_setup_resolver.rb « ci « resolvers « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f68d71174c3baed5802677c9e310e7d4767fb785 (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
# frozen_string_literal: true

module Resolvers
  module Ci
    class RunnerSetupResolver < BaseResolver
      type Types::Ci::RunnerSetupType, null: true

      argument :platform, GraphQL::STRING_TYPE,
        required: true,
        description: 'Platform to generate the instructions for'

      argument :architecture, GraphQL::STRING_TYPE,
        required: true,
        description: 'Architecture to generate the instructions for'

      argument :project_id, ::Types::GlobalIDType[::Project],
        required: false,
        description: 'Project to register the runner for'

      argument :group_id, ::Types::GlobalIDType[::Group],
        required: false,
        description: 'Group to register the runner for'

      def resolve(platform:, architecture:, **args)
        instructions = Gitlab::Ci::RunnerInstructions.new(
          current_user: current_user,
          os: platform,
          arch: architecture,
          **target_param(args)
        )

        {
          install_instructions: instructions.install_script || other_install_instructions(platform),
          register_instructions: instructions.register_command
        }
      ensure
        raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'User is not authorized to register a runner for the specified resource!' if instructions.errors.include?('Gitlab::Access::AccessDeniedError')
      end

      private

      def other_install_instructions(platform)
        Gitlab::Ci::RunnerInstructions::OTHER_ENVIRONMENTS[platform.to_sym][:installation_instructions_url]
      end

      def target_param(args)
        project_param(args[:project_id]) || group_param(args[:group_id]) || {}
      end

      def project_param(project_id)
        return unless project_id

        { project: find_object(project_id) }
      end

      def group_param(group_id)
        return unless group_id

        { group: find_object(group_id) }
      end

      def find_object(gid)
        GlobalID::Locator.locate(gid)
      end
    end
  end
end