Class: AuditEventService
- Inherits:
-
Object
- Object
- AuditEventService
- Includes:
- AuditEventSaveType
- Defined in:
- app/services/audit_event_service.rb
Constant Summary
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
Instantiates a new service.
-
#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.
Constructor Details
#initialize(author, entity, details = {}, save_type = :database_and_stream, created_at = DateTime.current) ⇒ AuditEventService
Instantiates a new service
20 21 22 23 24 25 26 27 |
# File 'app/services/audit_event_service.rb', line 20 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 end |
Instance Method Details
#for_authentication ⇒ AuditEventService
Builds the @details attribute for authentication
This uses the @author as the target object being audited
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/audit_event_service.rb', line 34 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
57 58 59 |
# File 'app/services/audit_event_service.rb', line 57 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
50 51 52 53 54 |
# File 'app/services/audit_event_service.rb', line 50 def security_event log_security_event_to_file log_authentication_event_to_database log_security_event_to_database end |