Class: SensitiveDataFilter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- SensitiveDataFilter
- Defined in:
- lib/AuthenticationSDK/logging/sensitive_logging.rb
Constant Summary collapse
- @@sensitiveTagConfig =
nil
- @@tagPatterns =
nil
- @@tagReplacements =
nil
- @@cardPatterns =
nil
Instance Method Summary collapse
- #call(severity, time, progname, msg) ⇒ Object
- #formatLogEntry(severity, time, progname, msg) ⇒ Object
-
#initialize ⇒ SensitiveDataFilter
constructor
A new instance of SensitiveDataFilter.
- #maskCreditCards(input) ⇒ Object
- #maskSensitiveString(input) ⇒ Object
Constructor Details
#initialize ⇒ SensitiveDataFilter
Returns a new instance of SensitiveDataFilter.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/AuthenticationSDK/logging/sensitive_logging.rb', line 54 def initialize @@sensitiveTagConfig = SensitiveDataConfigType.new @@cardPatterns = @@sensitiveTagConfig.sensitiveStringRegexes @@tagPatterns = Array.new(@@sensitiveTagConfig.sensitiveStringRegexes.length) @@tagReplacements = Array.new(@@sensitiveTagConfig.sensitiveTags.length) @@sensitiveTagConfig.sensitiveTags.each_with_index do |sensitiveTag, index| tagName = sensitiveTag.tagName replacement = sensitiveTag.replacement if sensitiveTag.pattern.nil? || sensitiveTag.pattern.empty? pattern = "(.*)" else pattern = sensitiveTag.pattern end @@tagPatterns[index] = "\""+tagName+"\":\""+pattern+"\"" @@tagReplacements[index] = "\""+tagName+"\":\""+replacement+"\"" end end |
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
75 76 77 78 79 |
# File 'lib/AuthenticationSDK/logging/sensitive_logging.rb', line 75 def call(severity, time, progname, msg) maskedMessage = maskSensitiveString(msg) ccMasked = maskCreditCards(maskedMessage) return formatLogEntry(severity, time, progname, ccMasked) end |
#formatLogEntry(severity, time, progname, msg) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/AuthenticationSDK/logging/sensitive_logging.rb', line 97 def formatLogEntry(severity, time, progname, msg) datetime = DateTime.now date_format = datetime.strftime("%Y-%m-%d %H:%M:%S") = "[#{date_format}] #{severity.ljust(10)} (#{progname}): #{msg}\n" # $stdout.puts log_message end |
#maskCreditCards(input) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/AuthenticationSDK/logging/sensitive_logging.rb', line 81 def maskCreditCards(input) encoded_input = input #.force_encoding("UTF-8") @@cardPatterns.each {|cardNumberRegex| encoded_input = encoded_input.gsub(/#{cardNumberRegex}/, "XXX") } return encoded_input end |
#maskSensitiveString(input) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/AuthenticationSDK/logging/sensitive_logging.rb', line 89 def maskSensitiveString(input) encoded_input = input #.force_encoding("UTF-8") @@tagPatterns.each_with_index do |item, index| encoded_input = encoded_input.gsub(/#{item}/,@@tagReplacements[index]) end return encoded_input end |