redactor

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Patterns []Pattern `json:"patterns"`
}

Config represents the redaction configuration

type Pattern

type Pattern struct {
	Name         string `json:"name"`
	Pattern      string `json:"pattern,omitempty"`
	Type         string `json:"type"`
	CaptureGroup int    `json:"capture_group,omitempty"`
	// FieldPattern is a regex that matches JSON field names. When set, only
	// values of matching fields are considered for redaction.
	FieldPattern string `json:"field_pattern,omitempty"`
}

Pattern represents a single redaction pattern.

There are two modes of operation:

  1. Value-based (FieldPattern empty): The Pattern regex is applied to all string values in the JSON. Use this for secrets with distinctive formats that can appear anywhere (API keys, tokens, etc.).
  1. Field-based (FieldPattern set): Only values of fields whose names match FieldPattern are redacted. The Pattern regex (if set) is applied to the field value; if Pattern is empty, the entire value is redacted.

type Redactor

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

Redactor handles redaction of sensitive data

func NewFromConfig

func NewFromConfig(cfg *config.RedactionConfig) (*Redactor, error)

NewFromConfig creates a new Redactor from a config.RedactionConfig. Returns nil if cfg is nil or if no patterns are configured. Note: This function does NOT check cfg.Enabled - callers should check that. If UseDefaultPatterns is true (default), default patterns are included. Custom patterns from cfg.Patterns are added after default patterns.

func NewRedactor

func NewRedactor(cfg Config) (*Redactor, error)

NewRedactor creates a new Redactor from a config

func (*Redactor) Redact

func (r *Redactor) Redact(input string) string

Redact redacts sensitive data from a string using value-based patterns only. Field-based patterns are skipped since plain text has no field context.

func (*Redactor) RedactJSONL

func (r *Redactor) RedactJSONL(input []byte) []byte

RedactJSONL redacts sensitive data from JSONL content by parsing each line, recursively redacting string values, and re-serializing. This ensures JSON structure is never corrupted by redaction patterns.

func (*Redactor) RedactJSONLine

func (r *Redactor) RedactJSONLine(line string) string

RedactJSONLine redacts a single JSON line, parsing it and applying redaction to string values only. Returns the redacted JSON. If the input is not valid JSON, falls back to text-based redaction.

Jump to

Keyboard shortcuts

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