Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/git_audit_event.rb')
-rw-r--r--lib/gitlab/git_audit_event.rb28
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