redact

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultReplace = "<REDACTED>"

DefaultReplace is the default string to include in place of matched redactions.

View Source
const EmailPattern = `([a-zA-Z0-9_.+-]+)@([a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)`

EmailPattern is a simple RegEx pattern intended to identify anything that looks like an email address.

View Source
const EmailReplace = "REDACTED@REDACTED"

EmailReplace is the default replacement pattern for email addresses. It includes the @ symbol to indicate it was an email address, but otherwise, the remainder of the address is redacted.

Variables

This section is empty.

Functions

func Apply

func Apply(redactions []*Redact, w io.Writer, r io.Reader) error

Apply takes a slice of redactions and a writer + reader, reading everything in and applying redactions in sequential order before writing. Therefore, each Redact that appears earlier in the list takes precedence over later Redacts. It is possible for redactions to collide with one another if a matcher can match with the Replace string of an earlier Redact.

func Bytes

func Bytes(b []byte, redactions []*Redact) ([]byte, error)

Bytes takes a byte slice and a slice of redactions, and wraps it with a reader and writer to apply the redactions, returning a string back. TODO(mkcp): Speed improvement & out of memory error: JSON responses can be really big, so we're going to have to chunk extremely large byte arrays down.

func JSON

func JSON(a any, redactions []*Redact) (any, error)

JSON accepts a json map or array and traverses the collections and redacts any strings we find.

func String

func String(result string, redactions []*Redact) (string, error)

String takes a string result and a slice of redactions, and wraps it with a reader and writer to apply the redactions, returning a string back. TODO(mkcp): Speed improvement & out of memory error: JSON responses can be really big, so we're going to have to chunk extremely large strings down.

Types

type Config

type Config struct {
	ID      string
	Matcher string
	Replace string
}

type Redact

type Redact struct {
	ID string `json:"ID"`

	Replace string `json:"replace"`
	// contains filtered or unexported fields
}

func Flatten

func Flatten(redacts ...[]*Redact) []*Redact

Flatten takes any number of slices of redacts and returns one slice containing all redacts in argument order

func MapNew

func MapNew(configs []Config) ([]*Redact, error)

MapNew takes a slice of RedactConfig and return a slice of redact.Redact

func New

func New(cfg Config) (*Redact, error)

New takes the matcher as a string and returned a compiled and ready-to-use redactor. ID and Replace are optional and can be left empty.

Jump to

Keyboard shortcuts

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