Class: AuthorizeNet::API::SensitiveDataFilter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- AuthorizeNet::API::SensitiveDataFilter
- Defined in:
- lib/authorize_net/api/SensitiveDataFilter.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
- #maskSensitiveXmlString(input) ⇒ Object
Constructor Details
#initialize ⇒ SensitiveDataFilter
Returns a new instance of SensitiveDataFilter.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/authorize_net/api/SensitiveDataFilter.rb', line 38 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+"</"+tagName+">" @@tagReplacements[index] = "<"+tagName+">"+replacement+"</"+tagName+">" end end |
Instance Method Details
#call(severity, time, progname, msg) ⇒ Object
59 60 61 62 63 |
# File 'lib/authorize_net/api/SensitiveDataFilter.rb', line 59 def call(severity, time, progname, msg) xmlMaskedLog = maskSensitiveXmlString(msg) ccMasked = maskCreditCards(xmlMaskedLog) return formatLogEntry(severity, time, progname, ccMasked) end |
#formatLogEntry(severity, time, progname, msg) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/authorize_net/api/SensitiveDataFilter.rb', line 81 def formatLogEntry(severity, time, progname, msg) constants = YAML.load_file(File.dirname(__FILE__) + "/constants.yml") progname = constants['clientId'] date_format = time.strftime("%Y-%m-%d %H:%M:%S") if severity == "INFO" or severity == "WARN" "[#{date_format}] #{severity} (#{progname}): #{msg}\n" else "[#{date_format}] #{severity} (#{progname}): #{msg}\n" end end |
#maskCreditCards(input) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/authorize_net/api/SensitiveDataFilter.rb', line 65 def maskCreditCards(input) input = input.force_encoding("UTF-8") @@cardPatterns.each {|cardNumberRegex| input = input.gsub(/#{cardNumberRegex}/, "XXX") } return input end |
#maskSensitiveXmlString(input) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/authorize_net/api/SensitiveDataFilter.rb', line 73 def maskSensitiveXmlString(input) input = input.force_encoding("UTF-8") @@tagPatterns.each_with_index do |item, index| input = input.gsub(/#{item}/,@@tagReplacements[index]) end return input end |