Documentation
¶
Overview ¶
Package audit writes and reads the audit log.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ActorFromContext = func(ctx context.Context) (Actor, bool) { return Actor{}, false }
ActorFromContext resolves the acting principal. The auth package (later in the boot order, so audit cannot import it) replaces this at init.
var SystemActor = Actor{Kind: "system", ID: "", Name: "system"}
SystemActor is recorded when no actor is found in the context.
Functions ¶
func IPFromContext ¶
IPFromContext returns the client IP stored by WithIP, or "".
func Migrations ¶
Migrations returns the audit_log migrations ("migrations/NNNN_x.sql").
Types ¶
type Actor ¶
type Actor struct{ Kind, ID, Name string }
Actor is who performed an action. Kinds: user, api_key, system, extension.
type Entry ¶
type Entry struct {
ID string `json:"id"`
At string `json:"at"`
Actor Actor `json:"actor"`
Action string `json:"action"`
TargetKind string `json:"target_kind"`
TargetID string `json:"target_id"`
IP string `json:"ip"`
Meta json.RawMessage `json:"meta"`
}
Entry is one audit_log row.
type ListQuery ¶
type ListQuery struct {
Action, ActorKind, ActorID, TargetKind, TargetID string
Since, Until string
Limit, Offset int
}
ListQuery filters List. Empty fields match everything. Since is inclusive and Until exclusive (RFC3339). Limit defaults to 50, max 500.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer records and lists audit entries.
func (*Writer) Record ¶
Record appends an entry. The actor comes from ActorFromContext (system when absent) and the IP from WithIP. The write ignores ctx cancellation so an entry is not lost when the request ends. Failures are logged, never returned, so auditing cannot break the audited operation.
Record writes on its own pool connection: never call it inside db.InTx (it would wait on the transaction's lock for busy_timeout and fail). Use RecordTx inside a transaction, or call Record after commit.