audit

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ExportMaxRows = 5000

ExportMaxRows is the export cap; exports beyond it truncate (surfaced by the endpoint via X-Truncated, not silently).

Variables

This section is empty.

Functions

func CSVCell

func CSVCell(s string) string

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

Types

type ListQuery

type ListQuery struct {
	WorkspaceID   string
	ActorID       string
	Action        string
	ResourceType  string
	From, To      *time.Time
	Limit, Offset int
}

type Recorder

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

func NewRecorder

func NewRecorder(pool *pgxpool.Pool, log *slog.Logger) *Recorder

func (*Recorder) CountFiltered added in v0.7.0

func (r *Recorder) CountFiltered(ctx context.Context, q ListQuery) (int, error)

CountFiltered returns how many audit events match q (no pagination) — the export endpoint exposes it so consumers can detect the 5000-row cap truncating their export instead of silently receiving fewer rows.

func (*Recorder) ExportCSV

func (r *Recorder) ExportCSV(ctx context.Context, q ListQuery, w io.Writer) (int, error)

func (*Recorder) List

func (r *Recorder) List(ctx context.Context, workspaceID string, limit int) ([]map[string]any, error)

func (*Recorder) Query

func (r *Recorder) Query(ctx context.Context, q ListQuery) ([]map[string]any, int, error)

func (*Recorder) Record

func (r *Recorder) Record(ctx context.Context, workspaceID *string, p *webx.Principal, action, resourceType, resourceID string, meta map[string]any)

func (*Recorder) RecordTx added in v0.4.0

func (r *Recorder) RecordTx(ctx context.Context, tx execer, workspaceID *string, p *webx.Principal, action, resourceType, resourceID string, meta map[string]any) error

RecordTx writes the audit entry inside the caller's transaction: failures return an error (the caller decides whether to roll back) - no swallowing, no detaching from the caller's ctx (opposite of Record's fire-and-forget). Product gates that need "business write and audit live or die together" should use this instead of hand-writing INSERT SQL (which silently decouples from schema evolution).

Directories

Path Synopsis
adapters

Jump to

Keyboard shortcuts

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