masking

package
v0.1.35 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package masking implements data-masking rules applied at display time to already-rendered message key/value strings. It never mutates raw bytes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action is what a rule does to the fields it affects.

const (
	ActionMask    Action = "MASK"    // class-wise char replacement
	ActionReplace Action = "REPLACE" // replace affected scalars with ***DATA_MASKED***
	ActionRemove  Action = "REMOVE"  // delete affected fields
)

type Masker

type Masker struct {
	// contains filtered or unexported fields
}

Masker applies a set of validated rules to rendered strings.

func New

func New(rules []Rule) (*Masker, error)

New builds a Masker from validated rules. New(nil) returns a no-op masker.

func (*Masker) Apply

func (m *Masker) Apply(content string, t Target) string

Apply returns the masked rendering of content for the given target.

type Rule

type Rule struct {
	Action     Action
	Keys       bool     // rule applies to message keys
	Values     bool     // rule applies to message values
	Fields     []string // explicit JSON field names to affect (XOR with FieldRegex)
	FieldRegex string   // regex matching JSON field names (XOR with Fields); neither set => all fields
}

Rule is one masking rule.

func ParseRules

func ParseRules(lines []string) ([]Rule, error)

ParseRules parses DSL lines from config into Rules. DSL per line: "ACTION scope=key|value|both [field=a,b,c | regex=REGEX]".

func (Rule) Validate

func (r Rule) Validate() error

Validate reports config errors.

type Target

type Target int

Target selects whether a rendering is a message key or value.

const (
	Key Target = iota
	Value
)

Jump to

Keyboard shortcuts

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