Module: Datadog::AppSec::Monitor::Gateway::Watcher

Defined in:
lib/datadog/appsec/monitor/gateway/watcher.rb

Overview

Watcher for Apssec internal events

Class Method Summary collapse

Class Method Details

.watchObject



14
15
16
17
18
# File 'lib/datadog/appsec/monitor/gateway/watcher.rb', line 14

def watch
  gateway = Instrumentation.gateway

  watch_user_id(gateway)
end

.watch_user_id(gateway = Instrumentation.gateway) ⇒ Object



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
60
61
# 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
          # TODO: should this hash be an Event instance instead?
          event = {
            waf_result: result,
            trace: scope.trace,
            span: scope.service_entry_span,
            user: user,
            actions: result.actions
          }

          if scope.service_entry_span
            scope.service_entry_span.set_tag('appsec.blocked', 'true') if result.actions.include?('block')
            scope.service_entry_span.set_tag('appsec.event', 'true')
          end

          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