audit

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package audit implements async event dispatching for security-relevant operations.

Components

  • Sink — interface for event consumers (channel, JSON writer, no-op).
  • Dispatcher — buffered async relay with drop-if-full / block-if-full semantics.
  • Event — structured audit record with timestamp, type, user, tenant, IP, metadata.

Architecture boundaries

This package owns event buffering and sink delivery. It does NOT decide which events to emit — that responsibility belongs to the Engine and flow functions.

What this package must NOT do

  • Filter or suppress events based on business logic.
  • Import goAuth or any sibling internal package.
  • Perform network I/O beyond what a caller-supplied Sink does.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelSink

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

ChannelSink writes audit events into a buffered channel.

func NewChannelSink

func NewChannelSink(buffer int) *ChannelSink

func (*ChannelSink) Emit

func (s *ChannelSink) Emit(ctx context.Context, event Event)

func (*ChannelSink) Events

func (s *ChannelSink) Events() <-chan Event

type Config

type Config struct {
	Enabled    bool
	BufferSize int
	DropIfFull bool
}

Config controls dispatcher buffering behavior.

type Dispatcher

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

Dispatcher asynchronously forwards audit events to a sink.

func NewDispatcher

func NewDispatcher(cfg Config, sink Sink) *Dispatcher

func (*Dispatcher) Close

func (d *Dispatcher) Close()

func (*Dispatcher) Dropped

func (d *Dispatcher) Dropped() uint64

func (*Dispatcher) Emit

func (d *Dispatcher) Emit(ctx context.Context, event Event)

func (*Dispatcher) SinkErrors added in v0.2.0

func (d *Dispatcher) SinkErrors() uint64

SinkErrors returns the number of sink-level write errors reported by the configured sink. Sinks that do not expose error counts return 0.

type Event

type Event struct {
	Timestamp time.Time         `json:"timestamp"`
	EventType string            `json:"event_type"`
	UserID    string            `json:"user_id,omitempty"`
	TenantID  string            `json:"tenant_id,omitempty"`
	SessionID string            `json:"session_id,omitempty"`
	IP        string            `json:"ip,omitempty"`
	Success   bool              `json:"success"`
	Error     string            `json:"error,omitempty"`
	Metadata  map[string]string `json:"metadata,omitempty"`
}

Event is the canonical audit event model used by internal dispatching and root APIs.

type JSONWriterSink

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

JSONWriterSink writes one JSON object per line.

func NewJSONWriterSink

func NewJSONWriterSink(w io.Writer) *JSONWriterSink

func (*JSONWriterSink) Emit

func (s *JSONWriterSink) Emit(ctx context.Context, event Event)

func (*JSONWriterSink) ErrorCount added in v0.2.0

func (s *JSONWriterSink) ErrorCount() uint64

ErrorCount returns the number of JSON encoding or write failures observed by this sink.

type NoOpSink

type NoOpSink struct{}

NoOpSink drops audit events.

func (NoOpSink) Emit

func (NoOpSink) Emit(context.Context, Event)

type Sink

type Sink interface {
	Emit(ctx context.Context, event Event)
}

Sink receives emitted audit events.

type SlogSink added in v0.2.0

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

SlogSink writes audit events through a slog.Logger for easy integration with structured log backends.

func NewSlogSink added in v0.2.0

func NewSlogSink(logger *slog.Logger) *SlogSink

NewSlogSink creates a SlogSink that writes audit events at info level.

func (*SlogSink) Emit added in v0.2.0

func (s *SlogSink) Emit(ctx context.Context, event Event)

Jump to

Keyboard shortcuts

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