Class: ReeAudit::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb

Overview

One audited action call. Built by the transport layer (the ree_roda plugin), enriched by the application through ReeAudit.annotate, and handed to a sink once the call is over.

Constant Summary collapse

STATUSES =
[:ok, :denied, :not_found, :error].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEvent

Returns a new instance of Event.



47
48
49
50
51
52
53
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 47

def initialize
  @sections = []
  @params = {}
  @annotations = {}
  @status = :ok
  @on_annotation = false
end

Instance Attribute Details

#accessorObject

Returns the value of attribute accessor.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def accessor
  @accessor
end

#action_nameObject

Returns the value of attribute action_name.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def action_name
  @action_name
end

#annotationsObject

Returns the value of attribute annotations.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def annotations
  @annotations
end

#duration_msObject

Returns the value of attribute duration_ms.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def duration_ms
  @duration_ms
end

#error_messageObject

Returns the value of attribute error_message.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def error_message
  @error_message
end

#error_typeObject

Returns the value of attribute error_type.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def error_type
  @error_type
end

#on_annotationObject

Returns the value of attribute on_annotation.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def on_annotation
  @on_annotation
end

#package_nameObject

Returns the value of attribute package_name.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def package_name
  @package_name
end

#paramsObject

Returns the value of attribute params.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def params
  @params
end

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def path
  @path
end

#request_methodObject

Returns the value of attribute request_method.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def request_method
  @request_method
end

#request_pathObject

Returns the value of attribute request_path.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def request_path
  @request_path
end

#sectionsObject

Returns the value of attribute sections.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def sections
  @sections
end

#started_atObject

Returns the value of attribute started_at.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def started_at
  @started_at
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def status
  @status
end

#summaryObject

Returns the value of attribute summary.



9
10
11
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 9

def summary
  @summary
end

Class Method Details

.build(action_name:, package_name: nil, summary: nil, sections: [], request_method: nil, path: nil, request_path: nil, params: {}, accessor: nil, on_annotation: false) ⇒ Object

Keyword-only on purpose: callers live in another package and must not depend on the order of the fields here.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 17

def build(
  action_name:,
  package_name: nil,
  summary: nil,
  sections: [],
  request_method: nil,
  path: nil,
  request_path: nil,
  params: {},
  accessor: nil,
  on_annotation: false
)
  event = new

  event.action_name = action_name
  event.package_name = package_name
  event.summary = summary
  event.sections = sections || []
  event.request_method = request_method
  event.path = path
  event.request_path = request_path
  event.params = params || {}
  event.accessor = accessor
  event.annotations = {}
  event.on_annotation = on_annotation

  event
end

Instance Method Details

#denied?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 59

def denied?
  status == :denied
end

#ok?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 55

def ok?
  status == :ok
end

#recordable?Boolean

An on_annotation event is the same call seen from two sides: the client asking for its own data, and a staff member asking for the client's. Only the code that resolved the caller can tell them apart, and it says so by annotating — so an untouched event of that kind is not worth recording.

Returns:

  • (Boolean)


67
68
69
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 67

def recordable?
  !on_annotation || !annotations.empty?
end

#to_hObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ree_lib/packages/ree_audit/package/ree_audit/event.rb', line 71

def to_h
  {
    action_name: action_name,
    package_name: package_name,
    summary: summary,
    sections: sections,
    request_method: request_method,
    path: path,
    request_path: request_path,
    params: params,
    status: status,
    error_type: error_type,
    error_message: error_message,
    started_at: started_at,
    duration_ms: duration_ms,
    annotations: annotations
  }
end