audit

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const JobName = "runa.audit"

Variables

This section is empty.

Functions

func DefaultMaskFields

func DefaultMaskFields() []string

DefaultMaskFields returns default sensitive field names.

func HandleDefaultQueue

func HandleDefaultQueue(handler func(context.Context, Entry) error, options ...queue.JobOption)

HandleDefaultQueue registers the audit queue handler on the default queue registry.

func HandleQueue

func HandleQueue(registry *queue.Registry, handler func(context.Context, Entry) error, options ...queue.JobOption)

HandleQueue registers the audit queue handler.

func Mask

func Mask(input core.Map, fields []string, value string) core.Map

Mask returns a copy of input with sensitive fields masked.

func Provider

func Provider(config Config) runaprovider.Provider

Provider registers audit config through Runa lifecycle.

func Record

func Record(ctx context.Context, writer Writer, entry Entry) error

Record writes one manual audit entry.

func Write

func Write(ctx context.Context, config Config, entry Entry) error

Write writes an audit entry using config writer and mode.

Types

type Config

type Config struct {
	Methods []string `toml:"methods"`
	Mode    Mode     `toml:"mode"`
	Strict  bool     `toml:"strict"`

	Write  func(ctx context.Context, entry Entry) error `toml:"-"`
	Writer Writer                                       `toml:"-"`

	CaptureInput bool     `toml:"capture_input"`
	MaskFields   []string `toml:"mask_fields"`
	MaskValue    string   `toml:"mask_value"`
	MaxInputSize int      `toml:"max_input_size"`

	Buffer       int           `toml:"buffer"`
	WriteTimeout time.Duration `toml:"write_timeout"`
}

Config configures audit middleware.

func Normalize

func Normalize(config Config) Config

Normalize fills audit config defaults.

type Data

type Data struct {
	Input core.Map
	Meta  core.Map
}

Data is used by manual audit recording helpers.

type Entry

type Entry struct {
	ID       string        `json:"id,omitempty"`
	Time     time.Time     `json:"time"`
	Method   string        `json:"method"`
	Path     string        `json:"path"`
	Route    string        `json:"route,omitempty"`
	Action   string        `json:"action,omitempty"`
	Status   int           `json:"status"`
	Success  bool          `json:"success"`
	Error    string        `json:"error,omitempty"`
	Duration time.Duration `json:"duration"`

	ActorID   string `json:"actor_id,omitempty"`
	ActorName string `json:"actor_name,omitempty"`
	Guard     string `json:"guard,omitempty"`

	IP        string `json:"ip,omitempty"`
	UserAgent string `json:"user_agent,omitempty"`
	RequestID string `json:"request_id,omitempty"`
	TraceID   string `json:"trace_id,omitempty"`

	Input core.Map `json:"input,omitempty"`
	Meta  core.Map `json:"meta,omitempty"`
}

Entry describes one business operation audit record.

type FuncWriter

type FuncWriter func(ctx context.Context, entry Entry) error

FuncWriter adapts a function to Writer.

func (FuncWriter) Write

func (fn FuncWriter) Write(ctx context.Context, entry Entry) error

Write writes an audit entry.

type Mode

type Mode string

Mode controls audit writing behavior.

const (
	Sync  Mode = "sync"
	Async Mode = "async"
)

type Registry

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

Registry stores normalized audit configuration.

func Default

func Default() *Registry

Default returns the default audit registry.

func New

func New(config Config) *Registry

New creates an audit registry from config.

func (*Registry) Config

func (registry *Registry) Config() Config

Config returns the normalized audit config.

type Writer

type Writer interface {
	Write(ctx context.Context, entry Entry) error
}

Writer writes audit entries.

func DefaultLogWriter

func DefaultLogWriter(channels ...string) Writer

DefaultLogWriter writes audit records to the default Runa logger registry.

func DefaultQueueWriter

func DefaultQueueWriter(queueName string, options ...queue.PushOption) Writer

DefaultQueueWriter pushes audit entries into the default queue registry.

func LogWriter

func LogWriter(registry *runlog.Registry, channels ...string) Writer

LogWriter writes audit records to a Runa logger registry.

func MultiWriter

func MultiWriter(writers ...Writer) Writer

MultiWriter combines multiple writers.

func NoopWriter

func NoopWriter() Writer

NoopWriter returns a writer that drops entries.

func QueueWriter

func QueueWriter(registry *queue.Registry, queueName string, options ...queue.PushOption) Writer

QueueWriter pushes audit entries into a Runa queue registry.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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