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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/datadog/appsec/monitor/gateway/watcher.rb', line 20
def watch_user_id(gateway = Instrumentation.gateway)
gateway.watch('identity.set_user', :appsec) do |stack, user|
block = false
event = nil
scope = Datadog::AppSec.active_scope
AppSec::Reactive::Operation.new('identity.set_user') do |op|
Monitor::Reactive::SetUser.subscribe(op, scope.processor_context) do |result|
if result.status == :match
event = {
waf_result: result,
trace: scope.trace,
span: scope.service_entry_span,
user: user,
actions: result.actions
}
scope.trace.keep! if scope.trace
Datadog::AppSec::Event.tag_and_keep!(scope, result)
scope.processor_context.events << event
end
end
block = Monitor::Reactive::SetUser.publish(op, user)
end
throw(Datadog::AppSec::Ext::INTERRUPT, [nil, [[:block, event]]]) if block
ret, res = stack.call(user)
if event
res ||= []
res << [:monitor, event]
end
[ret, res]
end
end
|