Class: Datadog::AppSec::WAF::Handle
- Inherits:
-
Object
- Object
- Datadog::AppSec::WAF::Handle
- Defined in:
- lib/datadog/appsec/waf/handle.rb
Overview
Ruby representation of the ddwaf_handle in libddwaf See github.com/DataDog/libddwaf/blob/10e3a1dfc7bc9bb8ab11a09a9f8b6b339eaf3271/BINDING_IMPL_NOTES.md?plain=1#L4-L19
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.
11 12 13 14 15 16 17 18 19 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 |
# File 'lib/datadog/appsec/waf/handle.rb', line 11 def initialize(rule, limits: {}, obfuscator: {}) rule_obj = Converter.ruby_to_object(rule) if rule_obj.null? || rule_obj[:type] == :ddwaf_object_invalid raise LibDDWAF::Error, "Could not convert object #{rule.inspect}" end config_obj = Datadog::AppSec::WAF::LibDDWAF::Config.new if config_obj.null? raise 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] = LibDDWAF::ObjectNoFree @config = config_obj diagnostics_obj = LibDDWAF::Object.new @handle_obj = LibDDWAF.ddwaf_init(rule_obj, config_obj, diagnostics_obj) @diagnostics = Converter.object_to_ruby(diagnostics_obj) if @handle_obj.null? raise LibDDWAF::Error.new('Could not create handle', diagnostics: @diagnostics) end validate! ensure LibDDWAF.ddwaf_object_free(diagnostics_obj) if diagnostics_obj LibDDWAF.ddwaf_object_free(rule_obj) if rule_obj end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/datadog/appsec/waf/handle.rb', line 9 def config @config end |
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
9 10 11 |
# File 'lib/datadog/appsec/waf/handle.rb', line 9 def diagnostics @diagnostics end |
#handle_obj ⇒ Object (readonly)
Returns the value of attribute handle_obj.
9 10 11 |
# File 'lib/datadog/appsec/waf/handle.rb', line 9 def handle_obj @handle_obj end |
Instance Method Details
#finalize ⇒ Object
47 48 49 50 51 |
# File 'lib/datadog/appsec/waf/handle.rb', line 47 def finalize invalidate! LibDDWAF.ddwaf_destroy(handle_obj) end |
#merge(data) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/datadog/appsec/waf/handle.rb', line 64 def merge(data) data_obj = Converter.ruby_to_object(data, coerce: false) diagnostics_obj = LibDDWAF::Object.new new_handle = LibDDWAF.ddwaf_update(handle_obj, data_obj, diagnostics_obj) return if new_handle.null? diagnostics = Converter.object_to_ruby(diagnostics_obj) new_from_handle(new_handle, diagnostics, config) ensure LibDDWAF.ddwaf_object_free(data_obj) if data_obj LibDDWAF.ddwaf_object_free(diagnostics_obj) if diagnostics_obj end |
#required_addresses ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/datadog/appsec/waf/handle.rb', line 53 def required_addresses valid! count = LibDDWAF::UInt32Ptr.new list = LibDDWAF.ddwaf_known_addresses(handle_obj, count) return [] if count == 0 # list is null list.get_array_of_string(0, count[:value]) end |