debian-mirror-gitlab/app/graphql/resolvers/ci/runner_setup_resolver.rb

79 lines
2.4 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
module Resolvers
module Ci
class RunnerSetupResolver < BaseResolver
2021-04-29 21:17:54 +05:30
ACCESS_DENIED = 'User is not authorized to register a runner for the specified resource!'
2021-01-29 00:20:46 +05:30
type Types::Ci::RunnerSetupType, null: true
2021-04-29 21:17:54 +05:30
description 'Runner setup instructions.'
2021-01-29 00:20:46 +05:30
2021-04-29 21:17:54 +05:30
argument :platform,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::String,
2021-04-29 21:17:54 +05:30
required: true,
description: 'Platform to generate the instructions for.'
2021-01-29 00:20:46 +05:30
2021-04-29 21:17:54 +05:30
argument :architecture,
2021-10-27 15:23:28 +05:30
type: GraphQL::Types::String,
2021-04-29 21:17:54 +05:30
required: true,
description: 'Architecture to generate the instructions for.'
2021-01-29 00:20:46 +05:30
2021-04-29 21:17:54 +05:30
argument :project_id,
type: ::Types::GlobalIDType[::Project],
required: false,
deprecated: { reason: 'No longer used', milestone: '13.11' },
description: 'Project to register the runner for.'
2021-01-29 00:20:46 +05:30
2021-04-29 21:17:54 +05:30
argument :group_id,
type: ::Types::GlobalIDType[::Group],
required: false,
deprecated: { reason: 'No longer used', milestone: '13.11' },
description: 'Group to register the runner for.'
2021-01-29 00:20:46 +05:30
def resolve(platform:, architecture:, **args)
instructions = Gitlab::Ci::RunnerInstructions.new(
2021-02-22 17:27:13 +05:30
os: platform,
2021-04-29 21:17:54 +05:30
arch: architecture
2021-01-29 00:20:46 +05:30
)
{
install_instructions: instructions.install_script || other_install_instructions(platform),
register_instructions: instructions.register_command
}
ensure
2021-04-29 21:17:54 +05:30
raise Gitlab::Graphql::Errors::ResourceNotAvailable, ACCESS_DENIED if access_denied?(instructions)
2021-01-29 00:20:46 +05:30
end
private
2021-04-29 21:17:54 +05:30
def access_denied?(instructions)
instructions.errors.include?('Gitlab::Access::AccessDeniedError')
end
2021-01-29 00:20:46 +05:30
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