Class: Ci::Runners::CreateRunnerService
- Inherits:
-
Object
- Object
- Ci::Runners::CreateRunnerService
- Includes:
- Gitlab::InternalEventsTracking
- Defined in:
- app/services/ci/runners/create_runner_service.rb
Constant Summary collapse
- RUNNER_CLASS_MAPPING =
{ 'instance_type' => Ci::Runners::RunnerCreationStrategies::InstanceRunnerStrategy, 'group_type' => Ci::Runners::RunnerCreationStrategies::GroupRunnerStrategy, 'project_type' => Ci::Runners::RunnerCreationStrategies::ProjectRunnerStrategy }.freeze
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(user:, params:) ⇒ CreateRunnerService
constructor
A new instance of CreateRunnerService.
- #normalize_params ⇒ Object
Methods included from Gitlab::InternalEventsTracking
Constructor Details
#initialize(user:, params:) ⇒ CreateRunnerService
Returns a new instance of CreateRunnerService.
14 15 16 17 18 19 |
# File 'app/services/ci/runners/create_runner_service.rb', line 14 def initialize(user:, params:) @user = user @scope = params[:scope] @params = params @strategy = RUNNER_CLASS_MAPPING[params[:runner_type]].new(user: user, params: params) end |
Instance Method Details
#execute ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/ci/runners/create_runner_service.rb', line 21 def execute normalize_params error = strategy.validate_params return ServiceResponse.error(message: error, reason: :validation_error) if error unless strategy. return ServiceResponse.error(message: _('Insufficient permissions'), reason: :forbidden) end should_mark_hosted = params.delete(:hosted_runner) runner = ::Ci::Runner.new(params) create_runner(runner, should_mark_hosted) end |
#normalize_params ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/services/ci/runners/create_runner_service.rb', line 37 def normalize_params params[:registration_type] = :authenticated_user params[:active] = !params.delete(:paused) if params.key?(:paused) params[:creator] = user strategy.normalize_params end |