Class: DecisionAgent::Auth::AccessAuditLogger
- Inherits:
-
Object
- Object
- DecisionAgent::Auth::AccessAuditLogger
- Defined in:
- lib/decision_agent/auth/access_audit_logger.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
-
#initialize(adapter: nil) ⇒ AccessAuditLogger
constructor
A new instance of AccessAuditLogger.
- #log_access(user_id:, action:, resource_type: nil, resource_id: nil, success: true) ⇒ Object
- #log_authentication(event_type, user_id:, email: nil, success: true, reason: nil) ⇒ Object
- #log_permission_check(user_id:, permission:, resource_type: nil, resource_id: nil, granted: true) ⇒ Object
- #query(filters = {}) ⇒ Object
Constructor Details
#initialize(adapter: nil) ⇒ AccessAuditLogger
Returns a new instance of AccessAuditLogger.
11 12 13 |
# File 'lib/decision_agent/auth/access_audit_logger.rb', line 11 def initialize(adapter: nil) @adapter = adapter || Audit::InMemoryAccessAdapter.new end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
9 10 11 |
# File 'lib/decision_agent/auth/access_audit_logger.rb', line 9 def adapter @adapter end |
Instance Method Details
#log_access(user_id:, action:, resource_type: nil, resource_id: nil, success: true) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/decision_agent/auth/access_audit_logger.rb', line 43 def log_access(user_id:, action:, resource_type: nil, resource_id: nil, success: true) log_entry = { event_type: "access", user_id: user_id, action: action.to_s, resource_type: resource_type, resource_id: resource_id, success: success, timestamp: Time.now.utc.iso8601 } @adapter.record_access(log_entry) end |
#log_authentication(event_type, user_id:, email: nil, success: true, reason: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/decision_agent/auth/access_audit_logger.rb', line 15 def log_authentication(event_type, user_id:, email: nil, success: true, reason: nil) log_entry = { event_type: event_type.to_s, user_id: user_id, email: email, success: success, reason: reason, timestamp: Time.now.utc.iso8601, ip_address: nil # Can be set by middleware } @adapter.record_access(log_entry) end |
#log_permission_check(user_id:, permission:, resource_type: nil, resource_id: nil, granted: true) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/decision_agent/auth/access_audit_logger.rb', line 29 def (user_id:, permission:, resource_type: nil, resource_id: nil, granted: true) log_entry = { event_type: "permission_check", user_id: user_id, permission: .to_s, resource_type: resource_type, resource_id: resource_id, granted: granted, timestamp: Time.now.utc.iso8601 } @adapter.record_access(log_entry) end |
#query(filters = {}) ⇒ Object
57 58 59 |
# File 'lib/decision_agent/auth/access_audit_logger.rb', line 57 def query(filters = {}) @adapter.query_access_logs(filters) end |