summaryrefslogtreecommitdiff
path: root/app/services/ci
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-24 09:14:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-24 09:14:06 +0000
commit563c8efdee39233f80f4dc7b20b38d417b26f055 (patch)
tree7b86eec1a8205b63c358f1004f20e5fbb52f1b4a /app/services/ci
parent89bfc148f90c410512f9c470ca1e50485b7000b2 (diff)
downloadgitlab-ce-563c8efdee39233f80f4dc7b20b38d417b26f055.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/ci')
-rw-r--r--app/services/ci/assign_runner_service.rb20
-rw-r--r--app/services/ci/register_runner_service.rb58
-rw-r--r--app/services/ci/runners/assign_runner_service.rb22
-rw-r--r--app/services/ci/runners/register_runner_service.rb60
-rw-r--r--app/services/ci/runners/unregister_runner_service.rb22
-rw-r--r--app/services/ci/runners/update_runner_service.rb21
-rw-r--r--app/services/ci/unregister_runner_service.rb20
-rw-r--r--app/services/ci/update_runner_service.rb19
8 files changed, 125 insertions, 117 deletions
diff --git a/app/services/ci/assign_runner_service.rb b/app/services/ci/assign_runner_service.rb
deleted file mode 100644
index 17526e17539..00000000000
--- a/app/services/ci/assign_runner_service.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-module Ci
- class AssignRunnerService
- # @param [Ci::Runner] runner the runner to assign to a project
- # @param [Project] project the new project to assign the runner to
- # @param [User] user the user performing the operation
- def initialize(runner, project, user)
- @runner = runner
- @project = project
- @user = user
- end
-
- def execute
- return false unless @user.present? && @user.can?(:assign_runner, @runner)
-
- @runner.assign_to(@project, @user)
- end
- end
-end
diff --git a/app/services/ci/register_runner_service.rb b/app/services/ci/register_runner_service.rb
deleted file mode 100644
index 7c6cd82565d..00000000000
--- a/app/services/ci/register_runner_service.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-# frozen_string_literal: true
-
-module Ci
- class RegisterRunnerService
- def execute(registration_token, attributes)
- runner_type_attrs = extract_runner_type_attrs(registration_token)
-
- return unless runner_type_attrs
-
- ::Ci::Runner.create(attributes.merge(runner_type_attrs))
- end
-
- private
-
- def extract_runner_type_attrs(registration_token)
- @attrs_from_token ||= check_token(registration_token)
-
- return unless @attrs_from_token
-
- attrs = @attrs_from_token.clone
- case attrs[:runner_type]
- when :project_type
- attrs[:projects] = [attrs.delete(:scope)]
- when :group_type
- attrs[:groups] = [attrs.delete(:scope)]
- end
-
- attrs
- end
-
- def check_token(registration_token)
- if runner_registration_token_valid?(registration_token)
- # Create shared runner. Requires admin access
- { runner_type: :instance_type }
- elsif runner_registrar_valid?('project') && project = ::Project.find_by_runners_token(registration_token)
- # Create a specific runner for the project
- { runner_type: :project_type, scope: project }
- elsif runner_registrar_valid?('group') && group = ::Group.find_by_runners_token(registration_token)
- # Create a specific runner for the group
- { runner_type: :group_type, scope: group }
- end
- end
-
- def runner_registration_token_valid?(registration_token)
- ActiveSupport::SecurityUtils.secure_compare(registration_token, Gitlab::CurrentSettings.runners_registration_token)
- end
-
- def runner_registrar_valid?(type)
- Feature.disabled?(:runner_registration_control) || Gitlab::CurrentSettings.valid_runner_registrars.include?(type)
- end
-
- def token_scope
- @attrs_from_token[:scope]
- end
- end
-end
-
-Ci::RegisterRunnerService.prepend_mod
diff --git a/app/services/ci/runners/assign_runner_service.rb b/app/services/ci/runners/assign_runner_service.rb
new file mode 100644
index 00000000000..0e16ac35231
--- /dev/null
+++ b/app/services/ci/runners/assign_runner_service.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module Ci
+ module Runners
+ class AssignRunnerService
+ # @param [Ci::Runner] runner the runner to assign to a project
+ # @param [Project] project the new project to assign the runner to
+ # @param [User] user the user performing the operation
+ def initialize(runner, project, user)
+ @runner = runner
+ @project = project
+ @user = user
+ end
+
+ def execute
+ return false unless @user.present? && @user.can?(:assign_runner, @runner)
+
+ @runner.assign_to(@project, @user)
+ end
+ end
+ end
+end
diff --git a/app/services/ci/runners/register_runner_service.rb b/app/services/ci/runners/register_runner_service.rb
new file mode 100644
index 00000000000..196d2de1a65
--- /dev/null
+++ b/app/services/ci/runners/register_runner_service.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+module Ci
+ module Runners
+ class RegisterRunnerService
+ def execute(registration_token, attributes)
+ runner_type_attrs = extract_runner_type_attrs(registration_token)
+
+ return unless runner_type_attrs
+
+ ::Ci::Runner.create(attributes.merge(runner_type_attrs))
+ end
+
+ private
+
+ def extract_runner_type_attrs(registration_token)
+ @attrs_from_token ||= check_token(registration_token)
+
+ return unless @attrs_from_token
+
+ attrs = @attrs_from_token.clone
+ case attrs[:runner_type]
+ when :project_type
+ attrs[:projects] = [attrs.delete(:scope)]
+ when :group_type
+ attrs[:groups] = [attrs.delete(:scope)]
+ end
+
+ attrs
+ end
+
+ def check_token(registration_token)
+ if runner_registration_token_valid?(registration_token)
+ # Create shared runner. Requires admin access
+ { runner_type: :instance_type }
+ elsif runner_registrar_valid?('project') && project = ::Project.find_by_runners_token(registration_token)
+ # Create a specific runner for the project
+ { runner_type: :project_type, scope: project }
+ elsif runner_registrar_valid?('group') && group = ::Group.find_by_runners_token(registration_token)
+ # Create a specific runner for the group
+ { runner_type: :group_type, scope: group }
+ end
+ end
+
+ def runner_registration_token_valid?(registration_token)
+ ActiveSupport::SecurityUtils.secure_compare(registration_token, Gitlab::CurrentSettings.runners_registration_token)
+ end
+
+ def runner_registrar_valid?(type)
+ Feature.disabled?(:runner_registration_control) || Gitlab::CurrentSettings.valid_runner_registrars.include?(type)
+ end
+
+ def token_scope
+ @attrs_from_token[:scope]
+ end
+ end
+ end
+end
+
+Ci::Runners::RegisterRunnerService.prepend_mod
diff --git a/app/services/ci/runners/unregister_runner_service.rb b/app/services/ci/runners/unregister_runner_service.rb
new file mode 100644
index 00000000000..4ee1e73c458
--- /dev/null
+++ b/app/services/ci/runners/unregister_runner_service.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module Ci
+ module Runners
+ class UnregisterRunnerService
+ attr_reader :runner, :author
+
+ # @param [Ci::Runner] runner the runner to unregister/destroy
+ # @param [User, authentication token String] author the user or the authentication token that authorizes the removal
+ def initialize(runner, author)
+ @runner = runner
+ @author = author
+ end
+
+ def execute
+ @runner&.destroy
+ end
+ end
+ end
+end
+
+Ci::Runners::UnregisterRunnerService.prepend_mod
diff --git a/app/services/ci/runners/update_runner_service.rb b/app/services/ci/runners/update_runner_service.rb
new file mode 100644
index 00000000000..6cc080f81c2
--- /dev/null
+++ b/app/services/ci/runners/update_runner_service.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+module Ci
+ module Runners
+ class UpdateRunnerService
+ attr_reader :runner
+
+ def initialize(runner)
+ @runner = runner
+ end
+
+ def update(params)
+ params[:active] = !params.delete(:paused) if params.include?(:paused)
+
+ runner.update(params).tap do |updated|
+ runner.tick_runner_queue if updated
+ end
+ end
+ end
+ end
+end
diff --git a/app/services/ci/unregister_runner_service.rb b/app/services/ci/unregister_runner_service.rb
deleted file mode 100644
index e7addb30b02..00000000000
--- a/app/services/ci/unregister_runner_service.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-module Ci
- class UnregisterRunnerService
- attr_reader :runner, :author
-
- # @param [Ci::Runner] runner the runner to unregister/destroy
- # @param [User, authentication token String] author the user or the authentication token that authorizes the removal
- def initialize(runner, author)
- @runner = runner
- @author = author
- end
-
- def execute
- @runner&.destroy
- end
- end
-end
-
-Ci::UnregisterRunnerService.prepend_mod
diff --git a/app/services/ci/update_runner_service.rb b/app/services/ci/update_runner_service.rb
deleted file mode 100644
index 4a17e25c0cc..00000000000
--- a/app/services/ci/update_runner_service.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-module Ci
- class UpdateRunnerService
- attr_reader :runner
-
- def initialize(runner)
- @runner = runner
- end
-
- def update(params)
- params[:active] = !params.delete(:paused) if params.include?(:paused)
-
- runner.update(params).tap do |updated|
- runner.tick_runner_queue if updated
- end
- end
- end
-end