Module: Datadog::AppSec::Processor::RuleMerger

Defined in:
lib/datadog/appsec/processor/rule_merger.rb

Overview

RuleMerger merge different sources of information into the rules payload

Defined Under Namespace

Classes: RuleVersionMismatchError

Constant Summary collapse

DEFAULT_WAF_PROCESSORS =
begin
  JSON.parse(Datadog::AppSec::Assets.waf_processors)
rescue StandardError => e
  Datadog.logger.error { "libddwaf rulemerger failed to parse default waf processors. Error: #{e.inspect}" }
  []
end
DEFAULT_WAF_SCANNERS =
begin
  JSON.parse(Datadog::AppSec::Assets.waf_scanners)
rescue StandardError => e
  Datadog.logger.error { "libddwaf rulemerger failed to parse default waf scanners. Error: #{e.inspect}" }
  []
end

Class Method Summary collapse

Class Method Details

.merge(rules:, data: [], overrides: [], exclusions: [], custom_rules: [], processors: DEFAULT_WAF_PROCESSORS, scanners: DEFAULT_WAF_SCANNERS) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/datadog/appsec/processor/rule_merger.rb', line 36

def merge(
  rules:, data: [], overrides: [], exclusions: [], custom_rules: [],
  processors: DEFAULT_WAF_PROCESSORS, scanners: DEFAULT_WAF_SCANNERS
)
  combined_rules = combine_rules(rules)

  combined_data = combine_data(data) if data.any?
  combined_overrides = combine_overrides(overrides) if overrides.any?
  combined_exclusions = combine_exclusions(exclusions) if exclusions.any?
  combined_custom_rules = combine_custom_rules(custom_rules) if custom_rules.any?

  combined_rules['rules_data'] = combined_data if combined_data
  combined_rules['rules_override'] = combined_overrides if combined_overrides
  combined_rules['exclusions'] = combined_exclusions if combined_exclusions
  combined_rules['custom_rules'] = combined_custom_rules if combined_custom_rules
  combined_rules['processors'] = processors
  combined_rules['scanners'] = scanners
  combined_rules
end