Module: Worldline::Acquiring::SDK::Logging::Obfuscation

Defined in:
lib/worldline/acquiring/sdk/logging/obfuscation/body_obfuscator.rb,
lib/worldline/acquiring/sdk/logging/obfuscation/obfuscation_rule.rb,
lib/worldline/acquiring/sdk/logging/obfuscation/header_obfuscator.rb,
lib/worldline/acquiring/sdk/logging/obfuscation/obfuscation_capable.rb

Defined Under Namespace

Modules: ObfuscationCapable Classes: BodyObfuscator, HeaderObfuscator

Class Method Summary collapse

Class Method Details

.obfuscate_allObject

Returns an obfuscation rule (callable) that will replace all characters with *



8
9
10
11
12
13
# File 'lib/worldline/acquiring/sdk/logging/obfuscation/obfuscation_rule.rb', line 8

def self.obfuscate_all
  ->(value) do
    return value if value.nil? or value.empty?
    '*' * (value || '').length
  end
end

.obfuscate_all_but_first(count) ⇒ Object

Returns an obfuscation rule (function) that will keep a fixed number of characters at the start, then replaces all other characters with *



22
23
24
25
26
27
28
29
30
31
# File 'lib/worldline/acquiring/sdk/logging/obfuscation/obfuscation_rule.rb', line 22

def self.obfuscate_all_but_first(count)
  ->(value) do
    return value if value.nil? or value.empty?
    return value if value.length < count
    # range describes the range of characters to replace with asterisks
    range = count...value.length
    value[range] = '*' * range.size
    value
  end
end

.obfuscate_all_but_last(count) ⇒ Object

Returns an obfuscation rule that will keep a fixed number of characters at the end, then replaces all other characters with *



35
36
37
38
39
40
41
42
43
44
# File 'lib/worldline/acquiring/sdk/logging/obfuscation/obfuscation_rule.rb', line 35

def self.obfuscate_all_but_last(count)
  ->(value) do
    return value if value.nil? or value.empty?
    return value if value.length < count
    # range describes the range of characters to replace with asterisks
    range = 0...(value.length - count)
    value[range] = '*' * range.size
    value
  end
end

.obfuscate_with_fixed_length(fixed_length) ⇒ Object

Returns an obfuscation rule (function) that will replace values with a fixed length string containing only *



16
17
18
# File 'lib/worldline/acquiring/sdk/logging/obfuscation/obfuscation_rule.rb', line 16

def self.obfuscate_with_fixed_length(fixed_length)
  ->(value) { '*' * fixed_length }
end