Class: Ci::Runners::RegisterRunnerService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/ci/runners/register_runner_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(registration_token, attributes) ⇒ RegisterRunnerService

Returns a new instance of RegisterRunnerService.



8
9
10
11
# File 'app/services/ci/runners/register_runner_service.rb', line 8

def initialize(registration_token, attributes)
  @registration_token = registration_token
  @attributes = attributes
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/ci/runners/register_runner_service.rb', line 13

def execute
  return ServiceResponse.error(message: 'invalid token supplied', http_status: :forbidden) unless attrs_from_token

  unless registration_token_allowed?(attrs_from_token)
    return ServiceResponse.error(
      message: 'runner registration disallowed',
      reason: :runner_registration_disallowed)
  end

  runner = ::Ci::Runner.new(attributes.merge(attrs_from_token))

  Ci::BulkInsertableTags.with_bulk_insert_tags do
    Ci::Runner.transaction do
      if runner.save
        Gitlab::Ci::Tags::BulkInsert.bulk_insert_tags!([runner])
      else
        raise ActiveRecord::Rollback
      end
    end
  end

  ServiceResponse.success(payload: { runner: runner })
end