Class: Datadog::AppSec::Processor::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/appsec/processor.rb

Overview

Context manages a sequence of runs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(processor) ⇒ Context

Returns a new instance of Context.



11
12
13
14
15
16
17
# File 'lib/datadog/appsec/processor.rb', line 11

def initialize(processor)
  @context = Datadog::AppSec::WAF::Context.new(processor.send(:handle))
  @time_ns = 0.0
  @time_ext_ns = 0.0
  @timeouts = 0
  @events = []
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



9
10
11
# File 'lib/datadog/appsec/processor.rb', line 9

def events
  @events
end

#time_ext_nsObject (readonly)

Returns the value of attribute time_ext_ns.



9
10
11
# File 'lib/datadog/appsec/processor.rb', line 9

def time_ext_ns
  @time_ext_ns
end

#time_nsObject (readonly)

Returns the value of attribute time_ns.



9
10
11
# File 'lib/datadog/appsec/processor.rb', line 9

def time_ns
  @time_ns
end

#timeoutsObject (readonly)

Returns the value of attribute timeouts.



9
10
11
# File 'lib/datadog/appsec/processor.rb', line 9

def timeouts
  @timeouts
end

Instance Method Details

#finalizeObject



35
36
37
# File 'lib/datadog/appsec/processor.rb', line 35

def finalize
  @context.finalize
end

#run(input, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/datadog/appsec/processor.rb', line 19

def run(input, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT)
  start_ns = Core::Utils::Time.get_time(:nanosecond)

  # TODO: remove multiple assignment
  _code, res = _ = @context.run(input, timeout)
  # @type var res: WAF::Result

  stop_ns = Core::Utils::Time.get_time(:nanosecond)

  @time_ns += res.total_runtime
  @time_ext_ns += (stop_ns - start_ns)
  @timeouts += 1 if res.timeout

  res
end