Class: Textus::Protocol::Handlers::Ops::AuditFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/protocol/handlers/ops/audit_filter.rb

Constant Summary collapse

FILTER_KEYS =
%i[key lane role verb since seq_since correlation_id limit].freeze

Instance Method Summary collapse

Instance Method Details

#call(ctx:, filters: {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/textus/protocol/handlers/ops/audit_filter.rb', line 8

def call(ctx:, filters: {})
  seq = filters[:seq_since]
  if seq
    min = ctx.audit_log.min_available
    raise Textus::CursorExpired.new(requested: seq, min_available: min) if min && seq < min - 1
  end

  rows = ctx.audit_log.list(seq_since: filters[:seq_since], key: filters[:key], role: filters[:role], verb: filters[:verb],
                            correlation_id: filters[:correlation_id], limit: filters[:limit]).select do |row|
    next false if filters[:lane] && !key_in_lane?(row["key"], filters[:lane], ctx)
    next false if filters[:since] && row["ts"] && Time.parse(row["ts"]) < filters[:since]

    true
  end
  { "verb" => "audit", "rows" => rows }
end