diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /app/services/ci/register_runner_service.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) | |
download | gitlab-ce-a7b3560714b4d9cc4ab32dffcd1f74a284b93580.tar.gz |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'app/services/ci/register_runner_service.rb')
-rw-r--r-- | app/services/ci/register_runner_service.rb | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/app/services/ci/register_runner_service.rb b/app/services/ci/register_runner_service.rb index 0a2027e33ce..7c6cd82565d 100644 --- a/app/services/ci/register_runner_service.rb +++ b/app/services/ci/register_runner_service.rb @@ -3,7 +3,7 @@ module Ci class RegisterRunnerService def execute(registration_token, attributes) - runner_type_attrs = check_token_and_extract_attrs(registration_token) + runner_type_attrs = extract_runner_type_attrs(registration_token) return unless runner_type_attrs @@ -12,16 +12,32 @@ module Ci private - def check_token_and_extract_attrs(registration_token) + 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, projects: [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, groups: [group] } + { runner_type: :group_type, scope: group } end end @@ -32,5 +48,11 @@ module Ci 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 |