Module: Datadog::AppSec::Monitor::Reactive::SetUser

Defined in:
lib/datadog/appsec/monitor/reactive/set_user.rb

Overview

Dispatch data from Datadog::Kit::Identity.set_user to the WAF context

Class Method Summary collapse

Class Method Details

.publish(op, user) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/datadog/appsec/monitor/reactive/set_user.rb', line 14

def self.publish(op, user)
  catch(:block) do
    op.publish('usr.id', user.id)

    nil
  end
end

.subscribe(op, waf_context) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/datadog/appsec/monitor/reactive/set_user.rb', line 22

def self.subscribe(op, waf_context)
  op.subscribe(*ADDRESSES) do |*values|
    Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }

    user_id = values[0]

    persistent_data = {
      'usr.id' => user_id,
    }

    waf_timeout = Datadog.configuration.appsec.waf_timeout
    result = waf_context.run(persistent_data, {}, waf_timeout)

    next if result.status != :match

    yield result
    throw(:block, true) unless result.actions.empty?
  end
end