github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/logging/obfuscation/ObfuscationRule.go (about) 1 package obfuscation 2 3 // Rule defines how a single value is obfuscated. 4 // This can be as simple as returning a fixed mask, or as complex as necessary. 5 type Rule func(value string) string 6 7 type ruleMap map[string]Rule 8 9 func (o ruleMap) obfuscateValue(key, value string) string { 10 rule, ok := o[key] 11 if ok == true { 12 return rule(value) 13 } 14 15 return value 16 } 17 18 // All returns an obfuscation rule that will replace all characters with *. 19 func All() Rule { 20 obfuscator := valueObfuscatorWithAll() 21 return obfuscator.obfuscateValue 22 } 23 24 // FixedLength returns an obfuscation rule that will replace values with a fixed length string containing only *. 25 func FixedLength(fixedLength int) Rule { 26 obfuscator := valueObfuscatorWithFixedLength(fixedLength) 27 return obfuscator.obfuscateValue 28 } 29 30 // KeepingStartCount returns an obfuscation rule that will keep a fixed number of characters at the start, 31 // then replaces all other characters with *. 32 func KeepingStartCount(count int) Rule { 33 obfuscator := valueObfuscatorWithKeepingStartCount(count) 34 return obfuscator.obfuscateValue 35 } 36 37 // KeepingEndCount returns an obfuscation rule that will keep a fixed number of characters at the end, 38 // then replaces all other characters with *. 39 func KeepingEndCount(count int) Rule { 40 obfuscator := valueObfuscatorWithKeepingEndCount(count) 41 return obfuscator.obfuscateValue 42 }