Class: Sentiero::Redaction::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sentiero/redaction/config.rb

Overview

Operator-facing redaction settings. The declarative subset serializes to the client (to_client_hash) and drives both engines; dom_patterns and server_proc are server-only.

Constant Summary collapse

URL_MODE_TO_CLIENT =
{strip: "strip", keep_all: "keepAll", keep_filtered: "keepFiltered"}.freeze
URL_MODE_FROM_CLIENT =
URL_MODE_TO_CLIENT.invert.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url_mode: :strip, url_param_allowlist: [], url_param_denylist: [], disabled_patterns: [], custom_patterns: [], dom_patterns: [], server_proc: nil) ⇒ Config

Returns a new instance of Config.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sentiero/redaction/config.rb', line 26

def initialize(url_mode: :strip, url_param_allowlist: [], url_param_denylist: [], disabled_patterns: [], custom_patterns: [], dom_patterns: [], server_proc: nil)
  @url_mode = url_mode
  @url_param_allowlist = url_param_allowlist
  @url_param_denylist = url_param_denylist
  @disabled_patterns = disabled_patterns
  @custom_patterns = custom_patterns
  # Symbols so `TEXT_PATTERN_ORDER - dom_patterns` in redact_dom_event works
  # even when an operator passes pattern names as strings.
  @dom_patterns = dom_patterns.map(&:to_sym)
  @server_proc = server_proc
end

Instance Attribute Details

#custom_patternsObject (readonly)

Returns the value of attribute custom_patterns.



10
11
12
# File 'lib/sentiero/redaction/config.rb', line 10

def custom_patterns
  @custom_patterns
end

#disabled_patternsObject (readonly)

Returns the value of attribute disabled_patterns.



10
11
12
# File 'lib/sentiero/redaction/config.rb', line 10

def disabled_patterns
  @disabled_patterns
end

#dom_patternsObject (readonly)

Returns the value of attribute dom_patterns.



10
11
12
# File 'lib/sentiero/redaction/config.rb', line 10

def dom_patterns
  @dom_patterns
end

#server_procObject

Returns the value of attribute server_proc.



9
10
11
# File 'lib/sentiero/redaction/config.rb', line 9

def server_proc
  @server_proc
end

#url_modeObject (readonly)

Returns the value of attribute url_mode.



10
11
12
# File 'lib/sentiero/redaction/config.rb', line 10

def url_mode
  @url_mode
end

Class Method Details

.from_client_hash(hash) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/sentiero/redaction/config.rb', line 15

def self.from_client_hash(hash)
  hash ||= {}
  new(
    url_mode: URL_MODE_FROM_CLIENT.fetch(hash["urlMode"], :strip),
    url_param_allowlist: hash["urlParamAllowlist"] || [],
    url_param_denylist: hash["urlParamDenylist"] || [],
    disabled_patterns: (hash["disabledPatterns"] || []).map(&:to_sym),
    custom_patterns: (hash["customPatterns"] || []).map { |s| Regexp.new(s) }
  )
end

Instance Method Details

#active_text_patternsObject



38
39
40
# File 'lib/sentiero/redaction/config.rb', line 38

def active_text_patterns
  TEXT_PATTERN_ORDER - disabled_patterns
end

#effective_allowlistObject



42
43
44
# File 'lib/sentiero/redaction/config.rb', line 42

def effective_allowlist
  @url_param_allowlist.map(&:downcase)
end

#effective_denylistObject



46
47
48
# File 'lib/sentiero/redaction/config.rb', line 46

def effective_denylist
  (BUILTIN_DENYLIST + @url_param_denylist.map(&:downcase)).uniq
end

#to_client_hashObject



50
51
52
53
54
55
56
57
58
# File 'lib/sentiero/redaction/config.rb', line 50

def to_client_hash
  {
    urlMode: URL_MODE_TO_CLIENT.fetch(url_mode, "strip"),
    urlParamAllowlist: effective_allowlist,
    urlParamDenylist: effective_denylist,
    disabledPatterns: disabled_patterns.map(&:to_s),
    customPatterns: custom_patterns.map(&:source)
  }
end