Class: Datadog::AppSec::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/appsec/processor.rb,
lib/datadog/appsec/processor/actions.rb,
lib/datadog/appsec/processor/rule_loader.rb,
lib/datadog/appsec/processor/rule_merger.rb

Overview

Processor integrates libddwaf into datadog/appsec

Defined Under Namespace

Modules: Actions, RuleLoader, RuleMerger Classes: Context

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ruleset:) ⇒ Processor

Returns a new instance of Processor.



76
77
78
79
80
81
82
83
84
# File 'lib/datadog/appsec/processor.rb', line 76

def initialize(ruleset:)
  @diagnostics = nil
  @addresses = []
  settings = Datadog.configuration.appsec

  unless load_libddwaf && create_waf_handle(settings, ruleset)
    Datadog.logger.warn { 'AppSec is disabled, see logged errors above' }
  end
end

Instance Attribute Details

#addressesObject (readonly)

Returns the value of attribute addresses.



74
75
76
# File 'lib/datadog/appsec/processor.rb', line 74

def addresses
  @addresses
end

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



74
75
76
# File 'lib/datadog/appsec/processor.rb', line 74

def diagnostics
  @diagnostics
end

Class Method Details

.libddwaf_platformObject



161
162
163
# File 'lib/datadog/appsec/processor.rb', line 161

def libddwaf_platform
  libddwaf_spec ? libddwaf_spec.platform.to_s : 'unknown'
end

.libddwaf_provides_waf?Boolean

check whether libddwaf is required and able to provide the needed feature

Returns:

  • (Boolean)


136
137
138
# File 'lib/datadog/appsec/processor.rb', line 136

def libddwaf_provides_waf?
  defined?(Datadog::AppSec::WAF) ? true : false
end

.libddwaf_specObject



157
158
159
# File 'lib/datadog/appsec/processor.rb', line 157

def libddwaf_spec
  Gem.loaded_specs['libddwaf']
end

.require_libddwafObject

libddwaf raises a LoadError on unsupported platforms; it may at some point succeed in being required yet not provide a specific needed feature.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/datadog/appsec/processor.rb', line 142

def require_libddwaf
  Datadog.logger.debug { "libddwaf platform: #{libddwaf_platform}" }

  require 'libddwaf'

  true
rescue LoadError => e
  Datadog.logger.error do
    'libddwaf failed to load,' \
      "installed platform: #{libddwaf_platform} ruby platforms: #{ruby_platforms} error: #{e.inspect}"
  end

  false
end

.ruby_platformsObject



165
166
167
# File 'lib/datadog/appsec/processor.rb', line 165

def ruby_platforms
  Gem.platforms.map(&:to_s)
end

Instance Method Details

#finalizeObject



90
91
92
# File 'lib/datadog/appsec/processor.rb', line 90

def finalize
  @handle.finalize
end

#ready?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/datadog/appsec/processor.rb', line 86

def ready?
  !@handle.nil?
end