Class: Datadog::AppSec::Context
- Inherits:
-
Object
- Object
- Datadog::AppSec::Context
- Defined in:
- lib/datadog/appsec/context.rb
Overview
This class accumulates the context over the request life-cycle and exposes interface sufficient for instrumentation to perform threat detection.
Constant Summary collapse
- ActiveContextError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#span ⇒ Object
readonly
Returns the value of attribute span.
-
#trace ⇒ Object
readonly
Returns the value of attribute trace.
-
#waf_runner ⇒ Object
readonly
NOTE: This is an intermediate state and will be changed.
Class Method Summary collapse
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(trace, span, security_engine) ⇒ Context
constructor
A new instance of Context.
- #run_rasp(_type, persistent_data, ephemeral_data, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT) ⇒ Object
- #run_waf(persistent_data, ephemeral_data, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT) ⇒ Object
Constructor Details
#initialize(trace, span, security_engine) ⇒ Context
Returns a new instance of Context.
34 35 36 37 38 39 |
# File 'lib/datadog/appsec/context.rb', line 34 def initialize(trace, span, security_engine) @trace = trace @span = span @security_engine = security_engine @waf_runner = security_engine.new_context end |
Instance Attribute Details
#span ⇒ Object (readonly)
Returns the value of attribute span.
10 11 12 |
# File 'lib/datadog/appsec/context.rb', line 10 def span @span end |
#trace ⇒ Object (readonly)
Returns the value of attribute trace.
10 11 12 |
# File 'lib/datadog/appsec/context.rb', line 10 def trace @trace end |
#waf_runner ⇒ Object (readonly)
NOTE: This is an intermediate state and will be changed
13 14 15 |
# File 'lib/datadog/appsec/context.rb', line 13 def waf_runner @waf_runner end |
Class Method Details
.activate(context) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/datadog/appsec/context.rb', line 16 def activate(context) raise ArgumentError, 'not a Datadog::AppSec::Context' unless context.instance_of?(Context) raise ActiveContextError, 'another context is active, nested contexts are not supported' if active Thread.current[Ext::ACTIVE_CONTEXT_KEY] = context end |
.active ⇒ Object
29 30 31 |
# File 'lib/datadog/appsec/context.rb', line 29 def active Thread.current[Ext::ACTIVE_CONTEXT_KEY] end |
.deactivate ⇒ Object
23 24 25 26 27 |
# File 'lib/datadog/appsec/context.rb', line 23 def deactivate active&.finalize ensure Thread.current[Ext::ACTIVE_CONTEXT_KEY] = nil end |
Instance Method Details
#finalize ⇒ Object
49 50 51 |
# File 'lib/datadog/appsec/context.rb', line 49 def finalize @waf_runner.finalize end |
#run_rasp(_type, persistent_data, ephemeral_data, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT) ⇒ Object
45 46 47 |
# File 'lib/datadog/appsec/context.rb', line 45 def run_rasp(_type, persistent_data, ephemeral_data, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT) @waf_runner.run(persistent_data, ephemeral_data, timeout) end |
#run_waf(persistent_data, ephemeral_data, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT) ⇒ Object
41 42 43 |
# File 'lib/datadog/appsec/context.rb', line 41 def run_waf(persistent_data, ephemeral_data, timeout = WAF::LibDDWAF::DDWAF_RUN_TIMEOUT) @waf_runner.run(persistent_data, ephemeral_data, timeout) end |