Class: Ingenico::Connect::SDK::Logging::Obfuscation::BodyObfuscator
- Inherits:
-
Object
- Object
- Ingenico::Connect::SDK::Logging::Obfuscation::BodyObfuscator
- Defined in:
- lib/ingenico/connect/sdk/logging/obfuscation/body_obfuscator.rb
Overview
A class that can be used to obfuscate properties in JSON bodies.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(additional_rules = nil) ⇒ BodyObfuscator
constructor
Creates a new body obfuscator.
-
#obfuscate_body(body) ⇒ String
Obfuscates the given body as necessary.
Constructor Details
#initialize(additional_rules = nil) ⇒ BodyObfuscator
Creates a new body obfuscator. This will contain some pre-defined obfuscation rules, as well as any provided custom rules
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ingenico/connect/sdk/logging/obfuscation/body_obfuscator.rb', line 14 def initialize(additional_rules=nil) @obfuscation_rules = { "cardNumber" => Obfuscation.obfuscate_all_but_last(4), "expiryDate" => Obfuscation.obfuscate_all_but_last(2), "cvv" => Obfuscation.obfuscate_all, "iban" => Obfuscation.obfuscate_all_but_last(4), "accountNumber" => Obfuscation.obfuscate_all_but_last(4), "reformattedAccountNumber" => Obfuscation.obfuscate_all_but_last(4), "bin" => Obfuscation.obfuscate_all_but_first(6), "value" => Obfuscation.obfuscate_all, "keyId" => Obfuscation.obfuscate_with_fixed_length(8), "secretKey" => Obfuscation.obfuscate_with_fixed_length(8), "publicKey" => Obfuscation.obfuscate_with_fixed_length(8), "userAuthenticationToken" => Obfuscation.obfuscate_with_fixed_length(8), "encryptedPayload" => Obfuscation.obfuscate_with_fixed_length(8), "decryptedPayload" => Obfuscation.obfuscate_with_fixed_length(8), "encryptedCustomerInput" => Obfuscation.obfuscate_with_fixed_length(8), } if additional_rules additional_rules.each do |name, rule| @obfuscation_rules[name] = rule end end @property_pattern = build_property_pattern(@obfuscation_rules.keys) end |
Class Method Details
.default_obfuscator ⇒ BodyObfuscator
92 93 94 |
# File 'lib/ingenico/connect/sdk/logging/obfuscation/body_obfuscator.rb', line 92 def self.default_obfuscator @@default_obfuscator end |
Instance Method Details
#obfuscate_body(body) ⇒ String
Obfuscates the given body as necessary.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ingenico/connect/sdk/logging/obfuscation/body_obfuscator.rb', line 72 def obfuscate_body(body) return nil if body.nil? return '' if body.empty? body.gsub(@property_pattern) do m = Regexp.last_match property_name = m[2] value = m[4] || m[5] # copy value 'cause it's part of m[0] m[0].sub(value, obfuscate_value(property_name, value.dup)) end end |