Class: SensitiveDataFilter

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/AuthenticationSDK/logging/sensitive_logging.rb

Constant Summary collapse

@@sensitiveTagConfig =
nil
@@tagPatterns =
nil
@@tagReplacements =
nil
@@cardPatterns =
nil

Instance Method Summary collapse

Constructor Details

#initializeSensitiveDataFilter

Returns a new instance of SensitiveDataFilter.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/AuthenticationSDK/logging/sensitive_logging.rb', line 51

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



72
73
74
75
76
# File 'lib/AuthenticationSDK/logging/sensitive_logging.rb', line 72

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



94
95
96
97
98
99
100
# File 'lib/AuthenticationSDK/logging/sensitive_logging.rb', line 94

def formatLogEntry(severity, time, progname, msg)
    datetime = DateTime.now
    date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
    log_message = "[#{date_format}] #{severity.ljust(10)} (#{progname}): #{msg}\n"
    # $stdout.puts log_message
    log_message
end

#maskCreditCards(input) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/AuthenticationSDK/logging/sensitive_logging.rb', line 78

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



86
87
88
89
90
91
92
# File 'lib/AuthenticationSDK/logging/sensitive_logging.rb', line 86

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