Class: Worldline::Connect::SDK::Logging::Obfuscation::HeaderObfuscator

Inherits:
Object
  • Object
show all
Defined in:
lib/worldline/connect/sdk/logging/obfuscation/header_obfuscator.rb

Overview

A class that can be used to obfuscate headers.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(additional_rules = nil) ⇒ HeaderObfuscator

Creates a new header obfuscator. This will contain some pre-defined obfuscation rules, as well as any provided custom rules

Parameters:

  • additional_rules (Hash) (defaults to: nil)

    An optional hash where the keys are header names and the values are functions that obfuscate a single value



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/worldline/connect/sdk/logging/obfuscation/header_obfuscator.rb', line 16

def initialize(additional_rules = nil)
  @obfuscation_rules = {
    "authorization" => Obfuscation.obfuscate_with_fixed_length(8),
    "www-authenticate" => Obfuscation.obfuscate_with_fixed_length(8),
    "proxy-authenticate" => Obfuscation.obfuscate_with_fixed_length(8),
    "proxy-authorization" => Obfuscation.obfuscate_with_fixed_length(8),
    "x-gcs-authentication-token" => Obfuscation.obfuscate_with_fixed_length(8),
    "x-gcs-callerpassword" => Obfuscation.obfuscate_with_fixed_length(8),
  }
  if additional_rules
    additional_rules.each do |name, rule|
      @obfuscation_rules[name.downcase] = rule
    end
  end
end

Class Method Details

.default_obfuscatorHeaderObfuscator

Returns:



48
49
50
# File 'lib/worldline/connect/sdk/logging/obfuscation/header_obfuscator.rb', line 48

def self.default_obfuscator
  DEFAULT_OBFUSCATOR
end

Instance Method Details

#obfuscate_header(header_name, value) ⇒ String

Obfuscates the value for the given header as necessary.

Returns:

  • (String)


35
36
37
38
39
# File 'lib/worldline/connect/sdk/logging/obfuscation/header_obfuscator.rb', line 35

def obfuscate_header(header_name, value)
  obfuscation_rule = @obfuscation_rules[header_name.downcase]
  return obfuscation_rule.call(value) if obfuscation_rule
  value
end