Module: Datadog::AppSec::Contrib::GraphQL::Gateway::Watcher

Defined in:
lib/datadog/appsec/contrib/graphql/gateway/watcher.rb

Overview

Watcher for Rack gateway events

Class Method Summary collapse

Class Method Details

.watchObject



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

def watch
  gateway = Instrumentation.gateway

  watch_multiplex(gateway)
end

.watch_multiplex(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
# File 'lib/datadog/appsec/contrib/graphql/gateway/watcher.rb', line 20

def watch_multiplex(gateway = Instrumentation.gateway)
  gateway.watch('graphql.multiplex', :appsec) do |stack, gateway_multiplex|
    context = AppSec::Context.active

    if context
      persistent_data = {
        'graphql.server.all_resolvers' => gateway_multiplex.arguments
      }

      result = context.run_waf(persistent_data, {}, Datadog.configuration.appsec.waf_timeout)

      if result.match?
        Datadog::AppSec::Event.tag_and_keep!(context, result)

        context.events << {
          waf_result: result,
          trace: context.trace,
          span: context.span,
          multiplex: gateway_multiplex,
          actions: result.actions
        }

        Datadog::AppSec::ActionsHandler.handle(result.actions)
      end
    end

    stack.call(gateway_multiplex.arguments)
  end
end