Documentation
¶
Overview ¶
Package audit is the platform's ONE audit writer: every service writes its own audit.<module>__* table through this package instead of hand-rolling INSERT statements per service. Record must be called inside the SAME transaction as the state change it documents (atomicity) — it takes a pgx.Tx, never a pool.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Denial ¶
func Denial(ctx context.Context, pool *pgxpool.Pool, w *Writer, actor, action, subject, reason string)
Denial best-effort records an authorization denial in its own transaction (denials are audited too). reason is the payload's `reason`: authz's own decision reason for a confirmed denial (403), or "AUTHORIZATION_UNAVAILABLE" when no definite answer was reached (503). A failure to write the denial row must not mask the response the caller already gets — it's logged nowhere here (the services have no logger wired in); the httpx.Recover middleware and access log still cover operational visibility.
Types ¶
type Event ¶
type Event struct {
Actor string
Action string
Subject string
Payload map[string]any
CorrelationID string
}
Event is one audit record. Actor MUST be derived server-side from the validated auth context — never from a request body. Payload is marshaled to JSON as-is; nil becomes an empty object. CorrelationID left empty is filled from ctx (the id httpx.Correlation stored there), so a handler that passes its request context through to Record gets the row joined to its request for free.
type Tx ¶
Tx is the subset of pgx.Tx that Record needs (structurally satisfied by *pgx.Tx and by sqlc's generated DBTX-backed transactions — no adapter required).
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer records events to one fixed, validated audit table.
func NewWriter ¶
NewWriter builds a Writer for the given fully-qualified audit table name (e.g. "audit.registry__events"). It returns an error if the name doesn't match the audit.<module>__<name> convention.