diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-19 15:57:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-19 15:57:54 +0300 |
commit | 419c53ec62de6e97a517abd5fdd4cbde3a942a34 (patch) | |
tree | 1f43a548b46bca8a5fb8fe0c31cef1883d49c5b6 /lib/gitlab/git_audit_event.rb | |
parent | 1da20d9135b3ad9e75e65b028bffc921aaf8deb7 (diff) |
Add latest changes from gitlab-org/gitlab@16-5-stable-eev16.5.0-rc42
Diffstat (limited to 'lib/gitlab/git_audit_event.rb')
-rw-r--r-- | lib/gitlab/git_audit_event.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/gitlab/git_audit_event.rb b/lib/gitlab/git_audit_event.rb new file mode 100644 index 00000000000..b8365bdf41f --- /dev/null +++ b/lib/gitlab/git_audit_event.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Gitlab + class GitAuditEvent # rubocop:disable Gitlab/NamespacedClass + attr_reader :project, :user, :author + + def initialize(player, project) + @project = project + @author = player.is_a?(::API::Support::GitAccessActor) ? player.deploy_key_or_user : player + @user = player.is_a?(::API::Support::GitAccessActor) ? player.user : player + end + + def send_audit_event(msg) + return if user.blank? || project.blank? + + audit_context = { + name: 'repository_git_operation', + stream_only: true, + author: author, + scope: project, + target: project, + message: msg + } + + ::Gitlab::Audit::Auditor.audit(audit_context) + end + end +end |