Documentation ¶
Index ¶
- Variables
- func ContextTransfer(ctx, targetCtx context.Context) context.Context
- func RedactionSchemeDoNothing() func(string) string
- func RedactionSchemeKeepLast(num int) func(string) string
- func RedactionSchemeKeepLastJWTNoSignature(num int) func(string) string
- type PatternRedactor
- func (r *PatternRedactor) AddPatterns(patterns ...*regexp.Regexp)
- func (r *PatternRedactor) Clone() *PatternRedactor
- func (r *PatternRedactor) Mask(data string) string
- func (r *PatternRedactor) RemovePattern(pattern *regexp.Regexp)
- func (r *PatternRedactor) SetScheme(scheme RedactionScheme)
- func (r *PatternRedactor) WithContext(ctx context.Context) context.Context
- type RedactionScheme
Constants ¶
This section is empty.
Variables ¶
var ( PatternIBAN = regexp.MustCompile( `[a-zA-Z]{2}` + `[0-9]{2}` + `(?:[ ]?[0-9a-zA-Z]{4})` + `(?:[ ]?[0-9]{4}){2,3}` + `(?:[ ]?[0-9]{1,2})?`, ) // All Visa card numbers start with a 4. New cards have 16 digits. Old cards have 13. PatternCCVisa = regexp.MustCompile(`4[0-9]{12}(?:[0-9]{3})?`) // MasterCard numbers either start with the numbers 51 through 55 or with the numbers 2221 through 2720. All have 16 digits. PatternCCMasterCard = regexp.MustCompile(`(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}`) // American Express card numbers start with 34 or 37 and have 15 digits. PatternCCAmericanExpress = regexp.MustCompile(`3[47][0-9]{13}`) // Diners Club card numbers begin with 300 through 305, 36 or 38. All have 14 digits. There are Diners Club cards that begin with 5 and have 16 digits. These are a joint venture between Diners Club and MasterCard, and should be processed like a MasterCard. PatternCCDinersClub = regexp.MustCompile(`3(?:0[0-5]|[68][0-9])[0-9]{11}`) // Discover card numbers begin with 6011 or 65. All have 16 digits. PatternCCDiscover = regexp.MustCompile(`6(?:011|5[0-9]{2})[0-9]{12}`) // JCB cards beginning with 2131 or 1800 have 15 digits. JCB cards beginning with 35 have 16 digits. PatternCCJCB = regexp.MustCompile(`(?:2131|1800|35\d{3})\d{11}`) // PatternJWT JsonWebToken PatternJWT = regexp.MustCompile(`(?:ey[a-zA-Z0-9=_-]+\.){2}[a-zA-Z0-9=_-]+`) //PatternBasicAuthBase match any: Basic YW55IGNhcm5hbCBwbGVhcw== does not validate base64 string PatternBasicAuthBase64 = regexp.MustCompile(`Authorization: Basic ([a-zA-Z0-9=]*)`) )
var AllPatterns = []*regexp.Regexp{ PatternIBAN, PatternJWT, PatternCCVisa, PatternCCMasterCard, PatternCCAmericanExpress, PatternCCDinersClub, PatternCCDiscover, PatternCCJCB, PatternBasicAuthBase64, }
AllPatterns is a list of all default redaction patterns
Functions ¶
func ContextTransfer ¶
ContextTransfer copies a request representation from one context to another.
func RedactionSchemeDoNothing ¶
RedactionSchemeDoNothing doesn't redact any values Note: only use for testing
func RedactionSchemeKeepLast ¶
RedactionSchemeKeepLast replaces all runes in the string with an asterisk except the last NUM runes
func RedactionSchemeKeepLastJWTNoSignature ¶
RedactionSchemeKeepLast replaces all runes in the string with an asterisk except the last NUM runes
Types ¶
type PatternRedactor ¶
type PatternRedactor struct {
// contains filtered or unexported fields
}
var Default *PatternRedactor
func Ctx ¶
func Ctx(ctx context.Context) *PatternRedactor
Ctx returns the PatternRedactor stored within the context. If no redactor has been defined, an empty redactor is returned that does nothing
func NewPatternRedactor ¶
func NewPatternRedactor(scheme RedactionScheme) *PatternRedactor
NewPatternRedactor creates a new redactor for masking certain patterns
func (*PatternRedactor) AddPatterns ¶
func (r *PatternRedactor) AddPatterns(patterns ...*regexp.Regexp)
AddPattern adds patterns to the redactor
func (*PatternRedactor) Clone ¶
func (r *PatternRedactor) Clone() *PatternRedactor
func (*PatternRedactor) Mask ¶
func (r *PatternRedactor) Mask(data string) string
func (*PatternRedactor) RemovePattern ¶
func (r *PatternRedactor) RemovePattern(pattern *regexp.Regexp)
RemovePattern deletes a pattern from the redactor
func (*PatternRedactor) SetScheme ¶
func (r *PatternRedactor) SetScheme(scheme RedactionScheme)
func (*PatternRedactor) WithContext ¶
func (r *PatternRedactor) WithContext(ctx context.Context) context.Context
WithContext allows storing the PatternRedactor inside a context for passing it on