Sha256: 70faf4384cf5e1e0c80a3d3f51178729334846ad74c6aa1f7b9e27527d7d8c3b

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Datadog
  module AppSec
    module Monitor
      module Reactive
        # Dispatch data from Datadog::Kit::Identity.set_user to the WAF context
        module SetUser
          ADDRESSES = [
            'usr.id',
          ].freeze
          private_constant :ADDRESSES

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

              nil
            end
          end

          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
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
datadog-2.8.0 lib/datadog/appsec/monitor/reactive/set_user.rb
datadog-2.7.1 lib/datadog/appsec/monitor/reactive/set_user.rb
datadog-2.7.0 lib/datadog/appsec/monitor/reactive/set_user.rb
datadog-2.6.0 lib/datadog/appsec/monitor/reactive/set_user.rb
datadog-2.5.0 lib/datadog/appsec/monitor/reactive/set_user.rb