redact

package
v0.4.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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=]*)`)
)

AllPatterns is a list of all default redaction patterns

Functions

func ContextTransfer

func ContextTransfer(ctx, targetCtx context.Context) context.Context

ContextTransfer copies a request representation from one context to another.

func RedactionSchemeDoNothing

func RedactionSchemeDoNothing() func(string) string

RedactionSchemeDoNothing doesn't redact any values Note: only use for testing

func RedactionSchemeKeepLast

func RedactionSchemeKeepLast(num int) func(string) string

RedactionSchemeKeepLast replaces all runes in the string with an asterisk except the last NUM runes

func RedactionSchemeKeepLastJWTNoSignature

func RedactionSchemeKeepLastJWTNoSignature(num int) func(string) string

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

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

type RedactionScheme

type RedactionScheme func(string) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL