Module: RoundhouseUi::Redaction

Defined in:
lib/roundhouse_ui/redaction.rb

Overview

Masks sensitive values when displaying job arguments. Configure the key patterns to redact (matched case-insensitively as substrings):

RoundhouseUi.redact_args = %w[password token secret api_key authorization]

Walks arrays/hashes so nested keyword args are covered. No-op by default.

Constant Summary collapse

MASK =
"«redacted»".freeze

Class Method Summary collapse

Class Method Details

.apply(value, patterns = RoundhouseUi.redact_args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/roundhouse_ui/redaction.rb', line 13

def apply(value, patterns = RoundhouseUi.redact_args)
  return value if patterns.nil? || patterns.empty?

  case value
  when Hash
    value.each_with_object({}) do |(k, v), out|
      out[k] = sensitive?(k, patterns) ? MASK : apply(v, patterns)
    end
  when Array
    value.map { |e| apply(e, patterns) }
  else
    value
  end
end

.sensitive?(key, patterns) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/roundhouse_ui/redaction.rb', line 28

def sensitive?(key, patterns)
  key = key.to_s.downcase
  patterns.any? { |p| key.include?(p.to_s.downcase) }
end