Class: SexySettings::SensitiveDataProtector
- Inherits:
-
Object
- Object
- SexySettings::SensitiveDataProtector
- Defined in:
- lib/sexy_settings/sensitive_data_protector.rb
Overview
This class holds logic sensitive data hiding
Constant Summary collapse
- PROTECTED_PROPERTIES =
[/pass(\z|word)/i, /_key\z/i, /secret/i, /token/i].freeze
- URL_REGEXP =
%r{\A(?:https?|ftp):\/\/(?:(?<userpass>.+)@)?.*:?(?:[^\/]*)}i
Instance Attribute Summary collapse
-
#prop ⇒ Object
readonly
Returns the value of attribute prop.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #hide_protected_data(value) ⇒ Object
- #hide_protected_data_in_url(value) ⇒ Object
-
#initialize(prop, value) ⇒ SensitiveDataProtector
constructor
A new instance of SensitiveDataProtector.
- #protected_userpass(value) ⇒ Object
- #protected_value ⇒ Object
Constructor Details
#initialize(prop, value) ⇒ SensitiveDataProtector
Returns a new instance of SensitiveDataProtector.
8 9 10 11 |
# File 'lib/sexy_settings/sensitive_data_protector.rb', line 8 def initialize(prop, value) @prop = prop @value = value.to_s end |
Instance Attribute Details
#prop ⇒ Object (readonly)
Returns the value of attribute prop.
6 7 8 |
# File 'lib/sexy_settings/sensitive_data_protector.rb', line 6 def prop @prop end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/sexy_settings/sensitive_data_protector.rb', line 6 def value @value end |
Instance Method Details
#hide_protected_data(value) ⇒ Object
19 20 21 22 23 |
# File 'lib/sexy_settings/sensitive_data_protector.rb', line 19 def hide_protected_data(value) return value if value.nil? return '********' if value.to_s.size <= 4 "********#{value.to_s[-4..-1]}" end |
#hide_protected_data_in_url(value) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/sexy_settings/sensitive_data_protector.rb', line 25 def hide_protected_data_in_url(value) return value if value.nil? || URL_REGEXP !~ value userpass = URL_REGEXP.match(value)[:userpass] return value if userpass.nil? || userpass.empty? value.sub(userpass, protected_userpass(userpass)) end |
#protected_userpass(value) ⇒ Object
32 33 34 |
# File 'lib/sexy_settings/sensitive_data_protector.rb', line 32 def protected_userpass(value) value.split(':', 2).compact.map(&method(:hide_protected_data)).join(':') end |
#protected_value ⇒ Object
13 14 15 16 17 |
# File 'lib/sexy_settings/sensitive_data_protector.rb', line 13 def protected_value return hide_protected_data_in_url(value) if /_url\z/ =~ prop return value unless PROTECTED_PROPERTIES.any? { |el| el =~ prop } hide_protected_data(value) end |