secret

package
v1.40.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package secret keeps secret values (GitLab tokens, API keys) out of logs, errors, and any user-facing output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogHandler

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

LogHandler wraps a slog.Handler so every message and attribute value is redacted before it reaches the underlying handler.

func NewLogHandler

func NewLogHandler(inner slog.Handler, r *Redactor) *LogHandler

NewLogHandler wraps inner with redaction from r.

func (*LogHandler) Enabled

func (h *LogHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*LogHandler) Handle

func (h *LogHandler) Handle(ctx context.Context, rec slog.Record) error

func (*LogHandler) WithAttrs

func (h *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*LogHandler) WithGroup

func (h *LogHandler) WithGroup(name string) slog.Handler

type Redactor

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

Redactor replaces registered secret values with a placeholder wherever they appear in strings, errors, or log records. It is safe for concurrent use.

func NewRedactor

func NewRedactor(values ...string) *Redactor

NewRedactor returns a Redactor for the given values. Empty values are ignored.

func (*Redactor) Add

func (r *Redactor) Add(value string)

Add registers another secret value to redact. Empty and very short values are ignored: redacting them would mangle unrelated text.

func (*Redactor) Redact

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

Redact returns s with all registered secrets replaced.

func (*Redactor) RedactError

func (r *Redactor) RedactError(err error) error

RedactError returns an error whose message has secrets redacted. The original error chain is preserved via %w only when nothing was redacted; otherwise the sanitized message replaces the chain so the secret cannot be recovered through Unwrap.

Jump to

Keyboard shortcuts

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