Class: Datadog::AppSec::WAF::Handle
- Inherits:
-
Object
- Object
- Datadog::AppSec::WAF::Handle
- Defined in:
- lib/datadog/appsec/waf.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
-
#handle_obj ⇒ Object
readonly
Returns the value of attribute handle_obj.
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(rule, limits: {}, obfuscator: {}) ⇒ Handle
constructor
A new instance of Handle.
- #merge(data) ⇒ Object
- #required_addresses ⇒ Object
Constructor Details
#initialize(rule, limits: {}, obfuscator: {}) ⇒ Handle
Returns a new instance of Handle.
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
# File 'lib/datadog/appsec/waf.rb', line 467 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] || LibDDWAF::DEFAULT_MAX_CONTAINER_SIZE config_obj[:limits][:max_container_depth] = limits[:max_container_depth] || LibDDWAF::DEFAULT_MAX_CONTAINER_DEPTH config_obj[:limits][:max_string_length] = limits[:max_string_length] || LibDDWAF::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] config_obj[:free_fn] = Datadog::AppSec::WAF::LibDDWAF::ObjectNoFree @config = config_obj diagnostics_obj = Datadog::AppSec::WAF::LibDDWAF::Object.new @handle_obj = Datadog::AppSec::WAF::LibDDWAF.ddwaf_init(rule_obj, config_obj, diagnostics_obj) @diagnostics = Datadog::AppSec::WAF.object_to_ruby(diagnostics_obj) if @handle_obj.null? fail LibDDWAF::Error.new('Could not create handle', diagnostics: @diagnostics) end validate! ensure Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(diagnostics_obj) if diagnostics_obj Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(rule_obj) if rule_obj end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
465 466 467 |
# File 'lib/datadog/appsec/waf.rb', line 465 def config @config end |
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
465 466 467 |
# File 'lib/datadog/appsec/waf.rb', line 465 def diagnostics @diagnostics end |
#handle_obj ⇒ Object (readonly)
Returns the value of attribute handle_obj.
465 466 467 |
# File 'lib/datadog/appsec/waf.rb', line 465 def handle_obj @handle_obj end |
Instance Method Details
#finalize ⇒ Object
503 504 505 506 507 |
# File 'lib/datadog/appsec/waf.rb', line 503 def finalize invalidate! Datadog::AppSec::WAF::LibDDWAF.ddwaf_destroy(handle_obj) end |
#merge(data) ⇒ Object
520 521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'lib/datadog/appsec/waf.rb', line 520 def merge(data) data_obj = Datadog::AppSec::WAF.ruby_to_object(data, coerce: false) diagnostics_obj = LibDDWAF::Object.new new_handle = Datadog::AppSec::WAF::LibDDWAF.ddwaf_update(handle_obj, data_obj, diagnostics_obj) return if new_handle.null? diagnostics = Datadog::AppSec::WAF.object_to_ruby(diagnostics_obj) new_from_handle(new_handle, diagnostics, config) ensure Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(data_obj) if data_obj Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(diagnostics_obj) if diagnostics_obj end |
#required_addresses ⇒ Object
509 510 511 512 513 514 515 516 517 518 |
# File 'lib/datadog/appsec/waf.rb', line 509 def required_addresses valid! 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 |