Class: Datadog::AppSec::SecurityEngine::Runner
- Inherits:
-
Object
- Object
- Datadog::AppSec::SecurityEngine::Runner
- Defined in:
- lib/datadog/appsec/security_engine/runner.rb
Overview
A class that check input via security engine (WAF) and respond with result.
Constant Summary collapse
- SUCCESSFUL_EXECUTION_CODES =
[:ok, :match].freeze
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(handle, telemetry:) ⇒ Runner
constructor
A new instance of Runner.
- #run(persistent_data, ephemeral_data, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT) ⇒ Object
Constructor Details
#initialize(handle, telemetry:) ⇒ Runner
Returns a new instance of Runner.
12 13 14 15 16 17 18 |
# File 'lib/datadog/appsec/security_engine/runner.rb', line 12 def initialize(handle, telemetry:) @mutex = Mutex.new @context = WAF::Context.new(handle) @telemetry = telemetry @debug_tag = "libddwaf:#{WAF::VERSION::STRING} method:ddwaf_run" end |
Instance Method Details
#finalize ⇒ Object
58 59 60 |
# File 'lib/datadog/appsec/security_engine/runner.rb', line 58 def finalize @context.finalize end |
#run(persistent_data, ephemeral_data, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT) ⇒ 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 |
# File 'lib/datadog/appsec/security_engine/runner.rb', line 20 def run(persistent_data, ephemeral_data, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT) @mutex.lock start_ns = Core::Utils::Time.get_time(:nanosecond) persistent_data.reject! do |_, v| next false if v.is_a?(TrueClass) || v.is_a?(FalseClass) v.nil? || v.empty? end ephemeral_data.reject! do |_, v| next false if v.is_a?(TrueClass) || v.is_a?(FalseClass) v.nil? || v.empty? end _code, result = try_run(persistent_data, ephemeral_data, timeout) stop_ns = Core::Utils::Time.get_time(:nanosecond) report_execution(result) unless SUCCESSFUL_EXECUTION_CODES.include?(result.status) return Result::Error.new(duration_ext_ns: stop_ns - start_ns) end klass = result.status == :match ? Result::Match : Result::Ok klass.new( events: result.events, actions: result.actions, derivatives: result.derivatives, timeout: result.timeout, duration_ns: result.total_runtime, duration_ext_ns: (stop_ns - start_ns) ) ensure @mutex.unlock end |