Class: Gitlab::GitAuditEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/git_audit_event.rb

Overview

rubocop:disable Gitlab/NamespacedClass

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(player, project) ⇒ GitAuditEvent

Returns a new instance of GitAuditEvent.



7
8
9
10
11
# File 'lib/gitlab/git_audit_event.rb', line 7

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

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



5
6
7
# File 'lib/gitlab/git_audit_event.rb', line 5

def author
  @author
end

#projectObject (readonly)

Returns the value of attribute project.



5
6
7
# File 'lib/gitlab/git_audit_event.rb', line 5

def project
  @project
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'lib/gitlab/git_audit_event.rb', line 5

def user
  @user
end

Instance Method Details

#send_audit_event(msg) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitlab/git_audit_event.rb', line 13

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