Class: Datadog::AppSec::WAF::Handle
- Inherits:
-
Object
- Object
- Datadog::AppSec::WAF::Handle
- Defined in:
- lib/datadog/appsec/waf.rb
Constant Summary collapse
- DEFAULT_MAX_CONTAINER_SIZE =
0- DEFAULT_MAX_CONTAINER_DEPTH =
0- DEFAULT_MAX_STRING_LENGTH =
0
Instance Attribute Summary collapse
-
#handle_obj ⇒ Object
readonly
Returns the value of attribute handle_obj.
-
#ruleset_info ⇒ Object
readonly
Returns the value of attribute ruleset_info.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(rule, limits: {}, obfuscator: {}) ⇒ Handle
constructor
A new instance of Handle.
- #required_addresses ⇒ Object
Constructor Details
#initialize(rule, limits: {}, obfuscator: {}) ⇒ Handle
Returns a new instance of Handle.
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/datadog/appsec/waf.rb', line 365 def initialize(rule, limits: {}, obfuscator: {}) rule_obj = Datadog::AppSec::WAF.ruby_to_object(rule) if rule_obj.null? || rule_obj[:type] == :ddwaf_object_invalid fail LibDDWAF::Error, "Could not convert object #{rule.inspect}" end config_obj = Datadog::AppSec::WAF::LibDDWAF::Config.new if config_obj.null? fail LibDDWAF::Error, 'Could not create config struct' end config_obj[:limits][:max_container_size] = limits[:max_container_size] || DEFAULT_MAX_CONTAINER_SIZE config_obj[:limits][:max_container_depth] = limits[:max_container_depth] || DEFAULT_MAX_CONTAINER_DEPTH config_obj[:limits][:max_string_length] = limits[:max_string_length] || DEFAULT_MAX_STRING_LENGTH config_obj[:obfuscator][:key_regex] = FFI::MemoryPointer.from_string(obfuscator[:key_regex]) if obfuscator[:key_regex] config_obj[:obfuscator][:value_regex] = FFI::MemoryPointer.from_string(obfuscator[:value_regex]) if obfuscator[:value_regex] ruleset_info = LibDDWAF::RuleSetInfo.new @handle_obj = Datadog::AppSec::WAF::LibDDWAF.ddwaf_init(rule_obj, config_obj, ruleset_info) @ruleset_info = { loaded: ruleset_info[:loaded], failed: ruleset_info[:failed], errors: WAF.object_to_ruby(ruleset_info[:errors]), version: ruleset_info[:version], } if @handle_obj.null? fail LibDDWAF::Error.new('Could not create handle', ruleset_info: @ruleset_info) end ObjectSpace.define_finalizer(self, Handle.finalizer(handle_obj)) ensure Datadog::AppSec::WAF::LibDDWAF.ddwaf_ruleset_info_free(ruleset_info) if ruleset_info Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(rule_obj) if rule_obj end |
Instance Attribute Details
#handle_obj ⇒ Object (readonly)
Returns the value of attribute handle_obj.
357 358 359 |
# File 'lib/datadog/appsec/waf.rb', line 357 def handle_obj @handle_obj end |
#ruleset_info ⇒ Object (readonly)
Returns the value of attribute ruleset_info.
363 364 365 |
# File 'lib/datadog/appsec/waf.rb', line 363 def ruleset_info @ruleset_info end |
Class Method Details
.finalizer(handle_obj) ⇒ Object
403 404 405 406 407 |
# File 'lib/datadog/appsec/waf.rb', line 403 def self.finalizer(handle_obj) proc do |object_id| Datadog::AppSec::WAF::LibDDWAF.ddwaf_destroy(handle_obj) end end |
Instance Method Details
#required_addresses ⇒ Object
409 410 411 412 413 414 415 416 |
# File 'lib/datadog/appsec/waf.rb', line 409 def required_addresses count = Datadog::AppSec::WAF::LibDDWAF::UInt32Ptr.new list = Datadog::AppSec::WAF::LibDDWAF.ddwaf_required_addresses(handle_obj, count) return [] if count == 0 # list is null list.get_array_of_string(0, count[:value]) end |