Class: NewStoreApi::AuditEvent

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/audit_event.rb

Overview

A single audit log event.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#actorActor

Who (or what) caused the audited change. Sourced from the caller's JWT; empty fields are omitted from the payload.

Returns:



16
17
18
# File 'lib/new_store_api/models/audit_event.rb', line 16

def actor
  @actor
end

#afterObject

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

Returns:

  • (Object)


23
24
25
# File 'lib/new_store_api/models/audit_event.rb', line 23

def after
  @after
end

#beforeObject

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

Returns:

  • (Object)


30
31
32
# File 'lib/new_store_api/models/audit_event.rb', line 30

def before
  @before
end

#created_atDateTime

When the audited change occurred (RFC 3339).

Returns:

  • (DateTime)


34
35
36
# File 'lib/new_store_api/models/audit_event.rb', line 34

def created_at
  @created_at
end

#event_idString

Unique identifier for the audit log event (UUIDv4).

Returns:

  • (String)


38
39
40
# File 'lib/new_store_api/models/audit_event.rb', line 38

def event_id
  @event_id
end

#levelString (readonly)

Log-level discriminator for downstream aggregators; always "AUDIT".

Returns:

  • (String)


42
43
44
# File 'lib/new_store_api/models/audit_event.rb', line 42

def level
  @level
end

#operationAuditOperationEnum

The operation performed on the resource.

Returns:



46
47
48
# File 'lib/new_store_api/models/audit_event.rb', line 46

def operation
  @operation
end

#requestRequestContext

The HTTP request that carried the audited change.

Returns:



50
51
52
# File 'lib/new_store_api/models/audit_event.rb', line 50

def request
  @request
end

#resourceString

The type of resource affected.

Returns:

  • (String)


54
55
56
# File 'lib/new_store_api/models/audit_event.rb', line 54

def resource
  @resource
end

#resource_idString

Identifier of the specific resource affected.

Returns:

  • (String)


58
59
60
# File 'lib/new_store_api/models/audit_event.rb', line 58

def resource_id
  @resource_id
end

#tenantString

Tenant the event belongs to.

Returns:

  • (String)


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

.namesObject

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

.nullablesObject

An array for nullable fields



90
91
92
# File 'lib/new_store_api/models/audit_event.rb', line 90

def self.nullables
  []
end

.optionalsObject

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

#inspectObject

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_atObject



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_sObject

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