Module: Datadog::AppSec::Assets

Defined in:
lib/datadog/appsec/assets.rb

Overview

Helper methods to get vendored assets

Class Method Summary collapse

Class Method Details

.blocked(format: :html) ⇒ Object



23
24
25
# File 'lib/datadog/appsec/assets.rb', line 23

def blocked(format: :html)
  (@blocked ||= {})[format] ||= read("blocked.#{format}")
end

.dirObject



39
40
41
42
43
# File 'lib/datadog/appsec/assets.rb', line 39

def dir
  # Happens only if this file is evaluated standalone, which should not happen
  # Necessary to make type-checker happy with a non-nilable return value
  __dir__ || raise('Unexpected file eval')
end

.filepath(filename) ⇒ Object



31
32
33
# File 'lib/datadog/appsec/assets.rb', line 31

def filepath(filename)
  path.join(filename)
end

.pathObject



27
28
29
# File 'lib/datadog/appsec/assets.rb', line 27

def path
  Pathname.new(dir).join('assets')
end

.read(filename, mode = 'rb') ⇒ Object



35
36
37
# File 'lib/datadog/appsec/assets.rb', line 35

def read(filename, mode = 'rb')
  File.open(filepath(filename), mode) { |f| f.read || raise('Unexpected nil IO object') }
end

.waf_processorsObject



15
16
17
# File 'lib/datadog/appsec/assets.rb', line 15

def waf_processors
  read('waf_rules/processors.json')
end

.waf_rules(kind = :recommended) ⇒ Object



11
12
13
# File 'lib/datadog/appsec/assets.rb', line 11

def waf_rules(kind = :recommended)
  read("waf_rules/#{kind}.json")
end

.waf_scannersObject



19
20
21
# File 'lib/datadog/appsec/assets.rb', line 19

def waf_scanners
  read('waf_rules/scanners.json')
end