Class: AuditEventService
- Inherits:
-
Object
- Object
- AuditEventService
- Defined in:
- app/services/audit_event_service.rb
Constant Summary
Constants included from Gitlab::Audit::Logging
Gitlab::Audit::Logging::ENTITY_TYPE_TO_CLASS
Constants included from AuditEventSaveType
AuditEventSaveType::SAVE_TYPES
Instance Method Summary collapse
-
#for_authentication ⇒ AuditEventService
Builds the @details attribute for authentication.
-
#initialize(author, entity, details = {}, save_type = :database_and_stream, created_at = DateTime.current) ⇒ AuditEventService
constructor
deprecated
Deprecated.
This service is deprecated. Use Gitlab::Audit::Auditor instead.
-
#log_security_event_to_file ⇒ Object
Writes event to a file.
-
#security_event ⇒ AuditEvent
Writes event to a file and creates an event record in DB.
Methods included from Gitlab::Audit::Logging
Constructor Details
#initialize(author, entity, details = {}, save_type = :database_and_stream, created_at = DateTime.current) ⇒ AuditEventService
Deprecated.
This service is deprecated. Use Gitlab::Audit::Auditor instead.
Instantiates a new service
More information: docs.gitlab.com/ee/development/audit_event_guide/#how-to-instrument-new-audit-events
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/audit_event_service.rb', line 25 def initialize(, entity, details = {}, save_type = :database_and_stream, created_at = DateTime.current) @author = () @entity = entity @details = details @ip_address = resolve_ip_address(@author) @save_type = save_type @created_at = created_at validate_scope!(@entity) log_initialization end |
Instance Method Details
#for_authentication ⇒ AuditEventService
Builds the @details attribute for authentication
This uses the @author as the target object being audited
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/services/audit_event_service.rb', line 43 def for_authentication mark_as_authentication_event! @details = { with: @details[:with], target_id: @author.id, target_type: 'User', target_details: @author.name } self end |
#log_security_event_to_file ⇒ Object
Writes event to a file
66 67 68 |
# File 'app/services/audit_event_service.rb', line 66 def log_security_event_to_file file_logger.info(base_payload.merge(formatted_details)) end |
#security_event ⇒ AuditEvent
Writes event to a file and creates an event record in DB
59 60 61 62 63 |
# File 'app/services/audit_event_service.rb', line 59 def security_event log_security_event_to_file log_authentication_event_to_database log_security_event_to_database end |