Class: Datadog::AppSec::WAF::Context
- Inherits:
-
Object
- Object
- Datadog::AppSec::WAF::Context
- Defined in:
- lib/datadog/appsec/waf.rb
Instance Attribute Summary collapse
-
#context_obj ⇒ Object
readonly
Returns the value of attribute context_obj.
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(handle) ⇒ Context
constructor
A new instance of Context.
- #run(input, timeout = LibDDWAF::DDWAF_RUN_TIMEOUT) ⇒ Object
Constructor Details
#initialize(handle) ⇒ Context
Returns a new instance of Context.
578 579 580 581 582 583 584 585 586 587 588 |
# File 'lib/datadog/appsec/waf.rb', line 578 def initialize(handle) handle_obj = handle.handle_obj retain(handle) @context_obj = Datadog::AppSec::WAF::LibDDWAF.ddwaf_context_init(handle_obj) if @context_obj.null? fail LibDDWAF::Error, 'Could not create context' end validate! end |
Instance Attribute Details
#context_obj ⇒ Object (readonly)
Returns the value of attribute context_obj.
576 577 578 |
# File 'lib/datadog/appsec/waf.rb', line 576 def context_obj @context_obj end |
Instance Method Details
#finalize ⇒ Object
590 591 592 593 594 595 596 597 598 599 600 |
# File 'lib/datadog/appsec/waf.rb', line 590 def finalize invalidate! retained.each do |retained_obj| next unless retained_obj.is_a?(Datadog::AppSec::WAF::LibDDWAF::Object) Datadog::AppSec::WAF::LibDDWAF.ddwaf_object_free(retained_obj) end Datadog::AppSec::WAF::LibDDWAF.ddwaf_context_destroy(context_obj) end |
#run(input, timeout = LibDDWAF::DDWAF_RUN_TIMEOUT) ⇒ Object
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/datadog/appsec/waf.rb', line 602 def run(input, timeout = LibDDWAF::DDWAF_RUN_TIMEOUT) valid! max_container_size = LibDDWAF::DDWAF_MAX_CONTAINER_SIZE max_container_depth = LibDDWAF::DDWAF_MAX_CONTAINER_DEPTH max_string_length = LibDDWAF::DDWAF_MAX_STRING_LENGTH input_obj = Datadog::AppSec::WAF.ruby_to_object(input, max_container_size: max_container_size, max_container_depth: max_container_depth, max_string_length: max_string_length) if input_obj.null? fail LibDDWAF::Error, "Could not convert input: #{input.inspect}" end result_obj = Datadog::AppSec::WAF::LibDDWAF::Result.new if result_obj.null? fail LibDDWAF::Error, "Could not create result object" end # retain C objects in memory for subsequent calls to run retain(input_obj) code = Datadog::AppSec::WAF::LibDDWAF.ddwaf_run(@context_obj, input_obj, result_obj, timeout) result = Result.new( RESULT_CODE[code], Datadog::AppSec::WAF.object_to_ruby(result_obj[:events]), result_obj[:total_runtime], result_obj[:timeout], Datadog::AppSec::WAF.object_to_ruby(result_obj[:actions]), ) [RESULT_CODE[code], result] ensure Datadog::AppSec::WAF::LibDDWAF.ddwaf_result_free(result_obj) if result_obj end |