Class: NewStoreApi::AuditEvent
- Defined in:
- lib/new_store_api/models/audit_event.rb
Overview
A single audit log event.
Instance Attribute Summary collapse
-
#actor ⇒ Actor
Who (or what) caused the audited change.
-
#after ⇒ Object
A point in time snapshot of the resource state before the change.
-
#before ⇒ Object
A point in time snapshot of the resource state before the change.
-
#created_at ⇒ DateTime
When the audited change occurred (RFC 3339).
-
#event_id ⇒ String
Unique identifier for the audit log event (UUIDv4).
-
#level ⇒ String
readonly
Log-level discriminator for downstream aggregators; always "AUDIT".
-
#operation ⇒ AuditOperationEnum
The operation performed on the resource.
-
#request ⇒ RequestContext
The HTTP request that carried the audited change.
-
#resource ⇒ String
The type of resource affected.
-
#resource_id ⇒ String
Identifier of the specific resource affected.
-
#tenant ⇒ String
Tenant the event belongs to.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#initialize(actor = nil, created_at = nil, event_id = nil, operation = nil, request = nil, resource = nil, resource_id = nil, tenant = nil, after = SKIP, before = SKIP) ⇒ AuditEvent
constructor
A new instance of AuditEvent.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
- #to_custom_created_at ⇒ Object
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(actor = nil, created_at = nil, event_id = nil, operation = nil, request = nil, resource = nil, resource_id = nil, tenant = nil, after = SKIP, before = SKIP) ⇒ AuditEvent
Returns a new instance of AuditEvent.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/new_store_api/models/audit_event.rb', line 94 def initialize(actor = nil, created_at = nil, event_id = nil, operation = nil, request = nil, resource = nil, resource_id = nil, tenant = nil, after = SKIP, before = SKIP) @actor = actor @after = after unless after == SKIP @before = before unless before == SKIP @created_at = created_at @event_id = event_id @level = 'AUDIT' @operation = operation @request = request @resource = resource @resource_id = resource_id @tenant = tenant end |
Instance Attribute Details
#actor ⇒ Actor
Who (or what) caused the audited change. Sourced from the caller's JWT; empty fields are omitted from the payload.
16 17 18 |
# File 'lib/new_store_api/models/audit_event.rb', line 16 def actor @actor end |
#after ⇒ Object
A point in time snapshot of the resource state before the change. Present for UPDATED and DELETED events. Unlike the rest of the event structure, the contents of this fields are not covered by the API's versioning and compatibility guarantees
23 24 25 |
# File 'lib/new_store_api/models/audit_event.rb', line 23 def after @after end |
#before ⇒ Object
A point in time snapshot of the resource state before the change. Present for UPDATED and DELETED events. Unlike the rest of the event structure, the contents of this fields are not covered by the API's versioning and compatibility guarantees
30 31 32 |
# File 'lib/new_store_api/models/audit_event.rb', line 30 def before @before end |
#created_at ⇒ DateTime
When the audited change occurred (RFC 3339).
34 35 36 |
# File 'lib/new_store_api/models/audit_event.rb', line 34 def created_at @created_at end |
#event_id ⇒ String
Unique identifier for the audit log event (UUIDv4).
38 39 40 |
# File 'lib/new_store_api/models/audit_event.rb', line 38 def event_id @event_id end |
#level ⇒ String (readonly)
Log-level discriminator for downstream aggregators; always "AUDIT".
42 43 44 |
# File 'lib/new_store_api/models/audit_event.rb', line 42 def level @level end |
#operation ⇒ AuditOperationEnum
The operation performed on the resource.
46 47 48 |
# File 'lib/new_store_api/models/audit_event.rb', line 46 def operation @operation end |
#request ⇒ RequestContext
The HTTP request that carried the audited change.
50 51 52 |
# File 'lib/new_store_api/models/audit_event.rb', line 50 def request @request end |
#resource ⇒ String
The type of resource affected.
54 55 56 |
# File 'lib/new_store_api/models/audit_event.rb', line 54 def resource @resource end |
#resource_id ⇒ String
Identifier of the specific resource affected.
58 59 60 |
# File 'lib/new_store_api/models/audit_event.rb', line 58 def resource_id @resource_id end |
#tenant ⇒ String
Tenant the event belongs to.
62 63 64 |
# File 'lib/new_store_api/models/audit_event.rb', line 62 def tenant @tenant end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/new_store_api/models/audit_event.rb', line 111 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. actor = Actor.from_hash(hash['actor']) if hash['actor'] created_at = if hash.key?('created_at') (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at']) end event_id = hash.key?('event_id') ? hash['event_id'] : nil operation = hash.key?('operation') ? hash['operation'] : nil request = RequestContext.from_hash(hash['request']) if hash['request'] resource = hash.key?('resource') ? hash['resource'] : nil resource_id = hash.key?('resource_id') ? hash['resource_id'] : nil tenant = hash.key?('tenant') ? hash['tenant'] : nil after = hash.key?('after') ? hash['after'] : SKIP before = hash.key?('before') ? hash['before'] : SKIP # Create object from extracted values. AuditEvent.new(actor, created_at, event_id, operation, request, resource, resource_id, tenant, after, before) end |
.names ⇒ Object
A mapping from model property names to API property names.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/new_store_api/models/audit_event.rb', line 65 def self.names @_hash = {} if @_hash.nil? @_hash['actor'] = 'actor' @_hash['after'] = 'after' @_hash['before'] = 'before' @_hash['created_at'] = 'created_at' @_hash['event_id'] = 'event_id' @_hash['level'] = 'level' @_hash['operation'] = 'operation' @_hash['request'] = 'request' @_hash['resource'] = 'resource' @_hash['resource_id'] = 'resource_id' @_hash['tenant'] = 'tenant' @_hash end |
.nullables ⇒ Object
An array for nullable fields
90 91 92 |
# File 'lib/new_store_api/models/audit_event.rb', line 90 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
82 83 84 85 86 87 |
# File 'lib/new_store_api/models/audit_event.rb', line 82 def self.optionals %w[ after before ] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
155 156 157 158 159 160 161 162 |
# File 'lib/new_store_api/models/audit_event.rb', line 155 def inspect class_name = self.class.name.split('::').last "<#{class_name} actor: #{@actor.inspect}, after: #{@after.inspect}, before:"\ " #{@before.inspect}, created_at: #{@created_at.inspect}, event_id: #{@event_id.inspect},"\ " level: #{@level.inspect}, operation: #{@operation.inspect}, request: #{@request.inspect},"\ " resource: #{@resource.inspect}, resource_id: #{@resource_id.inspect}, tenant:"\ " #{@tenant.inspect}>" end |
#to_custom_created_at ⇒ Object
141 142 143 |
# File 'lib/new_store_api/models/audit_event.rb', line 141 def to_custom_created_at DateTimeHelper.to_rfc3339(created_at) end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
146 147 148 149 150 151 152 |
# File 'lib/new_store_api/models/audit_event.rb', line 146 def to_s class_name = self.class.name.split('::').last "<#{class_name} actor: #{@actor}, after: #{@after}, before: #{@before}, created_at:"\ " #{@created_at}, event_id: #{@event_id}, level: #{@level}, operation: #{@operation},"\ " request: #{@request}, resource: #{@resource}, resource_id: #{@resource_id}, tenant:"\ " #{@tenant}>" end |