Class: Hoss::Transport::Filters::HashSanitizer Private
- Inherits:
-
Object
- Object
- Hoss::Transport::Filters::HashSanitizer
- Defined in:
- lib/hoss/transport/filters/hash_sanitizer.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- FILTERED =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'[FILTERED]'
- KEY_FILTERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ /passw(or)?d/i, /auth/i, /^pw$/, /secret/i, /token/i, /api[-._]?key/i, /session[-._]?id/i, /(set[-_])?cookie/i ].freeze
- VALUE_FILTERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[ # (probably) credit card number /^\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}$/ ].freeze
Instance Attribute Summary collapse
- #key_filters ⇒ Object private
Instance Method Summary collapse
- #filter_key?(key) ⇒ Boolean private
- #filter_value?(value) ⇒ Boolean private
-
#initialize ⇒ HashSanitizer
constructor
private
A new instance of HashSanitizer.
- #strip_from!(obj, key_filters = KEY_FILTERS) ⇒ Object private
Constructor Details
#initialize ⇒ HashSanitizer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of HashSanitizer.
44 45 46 |
# File 'lib/hoss/transport/filters/hash_sanitizer.rb', line 44 def initialize @key_filters = KEY_FILTERS end |
Instance Attribute Details
#key_filters ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 |
# File 'lib/hoss/transport/filters/hash_sanitizer.rb', line 42 def key_filters @key_filters end |
Instance Method Details
#filter_key?(key) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 |
# File 'lib/hoss/transport/filters/hash_sanitizer.rb', line 67 def filter_key?(key) @key_filters.any? { |regex| regex.match(key) } end |
#filter_value?(value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 |
# File 'lib/hoss/transport/filters/hash_sanitizer.rb', line 71 def filter_value?(value) VALUE_FILTERS.any? { |regex| regex.match(value) } end |
#strip_from!(obj, key_filters = KEY_FILTERS) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hoss/transport/filters/hash_sanitizer.rb', line 48 def strip_from!(obj, key_filters = KEY_FILTERS) return unless obj&.is_a?(Hash) obj.each do |k, v| if filter_key?(k) next obj[k] = FILTERED end case v when Hash strip_from!(v) when String if filter_value?(v) obj[k] = FILTERED end end end end |