Class: Kitsune::Kit::SecretFilter
- Inherits:
-
Object
- Object
- Kitsune::Kit::SecretFilter
- Defined in:
- lib/kitsune/kit/secret_filter.rb
Constant Summary collapse
- REDACTED =
"[REDACTED]"- SENSITIVE_KEY =
/(token|secret|password|private_key|authorization)/i- PRIVATE_KEY_BLOCK =
/-----BEGIN [^-\r\n]*PRIVATE KEY-----.*?-----END [^-\r\n]*PRIVATE KEY-----/m
Instance Method Summary collapse
- #filter(value) ⇒ Object
-
#initialize(values = []) ⇒ SecretFilter
constructor
A new instance of SecretFilter.
- #register(value) ⇒ Object
Constructor Details
#initialize(values = []) ⇒ SecretFilter
Returns a new instance of SecretFilter.
12 13 14 15 |
# File 'lib/kitsune/kit/secret_filter.rb', line 12 def initialize(values = []) @values = [] values.each { |value| register(value) } end |
Instance Method Details
#filter(value) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/kitsune/kit/secret_filter.rb', line 23 def filter(value) case value when Hash value.each_with_object({}) do |(key, item), result| result[key] = key.to_s.match?(SENSITIVE_KEY) ? REDACTED : filter(item) end when Array value.map { |item| filter(item) } when String filter_string(value) else value end end |
#register(value) ⇒ Object
17 18 19 20 21 |
# File 'lib/kitsune/kit/secret_filter.rb', line 17 def register(value) string = value.to_s @values << string unless string.empty? || @values.include?(string) self end |