Class: Legion::Data::Model::AuditLog

Inherits:
Object
  • Object
show all
Includes:
Logging::Helper
Defined in:
lib/legion/data/models/audit_log.rb

Constant Summary collapse

VALID_EVENT_TYPES =
%w[runner_execution lifecycle_transition].freeze
VALID_STATUSES =
%w[success failure denied].freeze

Instance Method Summary collapse

Methods included from Logging::Helper

#handle_exception

Instance Method Details

#before_destroyObject



33
34
35
# File 'lib/legion/data/models/audit_log.rb', line 33

def before_destroy
  raise 'audit_log records are immutable and cannot be deleted'
end

#before_updateObject



29
30
31
# File 'lib/legion/data/models/audit_log.rb', line 29

def before_update
  raise 'audit_log records are immutable and cannot be updated'
end

#parsed_detailObject



20
21
22
23
24
25
26
27
# File 'lib/legion/data/models/audit_log.rb', line 20

def parsed_detail
  return nil unless detail

  Legion::JSON.load(detail)
rescue StandardError => e
  handle_exception(e, level: :warn, handled: true, operation: :parsed_detail, id: self[:id])
  nil
end

#validateObject



14
15
16
17
18
# File 'lib/legion/data/models/audit_log.rb', line 14

def validate
  super
  errors.add(:event_type, 'invalid') unless VALID_EVENT_TYPES.include?(event_type)
  errors.add(:status, 'invalid')     unless VALID_STATUSES.include?(status)
end