diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /lib/gitlab/audit | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'lib/gitlab/audit')
-rw-r--r-- | lib/gitlab/audit/ci_runner_token_author.rb | 41 | ||||
-rw-r--r-- | lib/gitlab/audit/null_author.rb | 14 |
2 files changed, 52 insertions, 3 deletions
diff --git a/lib/gitlab/audit/ci_runner_token_author.rb b/lib/gitlab/audit/ci_runner_token_author.rb new file mode 100644 index 00000000000..5f83725b5a3 --- /dev/null +++ b/lib/gitlab/audit/ci_runner_token_author.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Gitlab + module Audit + class CiRunnerTokenAuthor < Gitlab::Audit::NullAuthor + # Represents a CI Runner token (registration or authentication) + # + # @param [AuditEvent] audit_event event representing a runner registration/un-registration operation + def initialize(audit_event) + if audit_event.details.include?(:runner_authentication_token) + token = audit_event.details[:runner_authentication_token] + name = "Authentication token: #{token}" + elsif audit_event.details.include?(:runner_registration_token) + token = audit_event.details[:runner_registration_token] + name = "Registration token: #{token}" + else + raise ArgumentError, 'Runner token missing' + end + + super(id: -1, name: name) + + @entity_type = audit_event.entity_type + @entity_path = audit_event.entity_path + end + + def full_path + url_helpers = ::Gitlab::Routing.url_helpers + + case @entity_type + when 'Group' + url_helpers.group_settings_ci_cd_path(@entity_path, anchor: 'js-runners-settings') + when 'Project' + project = Project.find_by_full_path(@entity_path) + url_helpers.project_settings_ci_cd_path(project, anchor: 'js-runners-settings') if project + else + url_helpers.admin_runners_path + end + end + end + end +end diff --git a/lib/gitlab/audit/null_author.rb b/lib/gitlab/audit/null_author.rb index 0b0e6a46fe4..80e0c4ddf58 100644 --- a/lib/gitlab/audit/null_author.rb +++ b/lib/gitlab/audit/null_author.rb @@ -14,9 +14,13 @@ module Gitlab # @param [Integer] id # @param [String] name # - # @return [Gitlab::Audit::UnauthenticatedAuthor, Gitlab::Audit::DeletedAuthor] - def self.for(id, name) - if id == -1 + # @return [Gitlab::Audit::UnauthenticatedAuthor, Gitlab::Audit::DeletedAuthor, Gitlab::Audit::CiRunnerTokenAuthor] + def self.for(id, audit_event) + name = audit_event[:author_name] || audit_event.details[:author_name] + + if audit_event.target_type == ::Ci::Runner.name + Gitlab::Audit::CiRunnerTokenAuthor.new(audit_event) + elsif id == -1 Gitlab::Audit::UnauthenticatedAuthor.new(name: name) else Gitlab::Audit::DeletedAuthor.new(id: id, name: name) @@ -31,6 +35,10 @@ module Gitlab def current_sign_in_ip nil end + + def full_path + nil + end end end end |