redact

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package redact handles regex-based field redaction for Keep's redact action.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyMutations

func ApplyMutations(params map[string]any, mutations []Mutation) map[string]any

ApplyMutations returns a new params map with mutations applied. The original map is not modified. Deep-copies the map structure.

Types

type CompiledPattern

type CompiledPattern struct {
	Regex   *regexp.Regexp
	Replace string
}

CompiledPattern is a pre-compiled redact pattern.

func CompilePatterns

func CompilePatterns(patterns []config.RedactPattern) ([]CompiledPattern, error)

CompilePatterns compiles a list of config redact patterns into CompiledPatterns.

type Mutation

type Mutation struct {
	Path string
	// Original holds the pre-redaction value. It is populated for audit
	// purposes but MUST NOT be returned to the calling agent or exposed
	// externally. Callers should strip this field before serializing
	// the result outside the engine.
	Original string `json:"-"`
	Replaced string
}

Mutation describes a single field change.

func Apply

func Apply(params map[string]any, target string, patterns []CompiledPattern) []Mutation

Apply runs compiled patterns against the string value at the given field path in params. Returns the list of mutations (empty if no patterns matched). Does not modify params.

The target path uses the form "params.field" or "params.nested.field". The "params." prefix is stripped before navigating the map.

Jump to

Keyboard shortcuts

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