Documentation
¶
Overview ¶
Package adminaudit records admin actions: who did what to whom, when and from where. Rows are written before the action runs (so an action cannot happen unrecorded) and finished with the outcome afterwards.
Index ¶
- Constants
- func Clean(in map[string]any) map[string]any
- type Entry
- type Filter
- type Row
- type Store
- func (s *Store) Begin(ctx context.Context, e Entry) (int64, error)
- func (s *Store) Finish(ctx context.Context, id int64, status int) error
- func (s *Store) List(ctx context.Context, f Filter) ([]Row, int64, error)
- func (s *Store) NoteImpersonationStart(ctx context.Context, admin, target uuid.UUID, ip string, window time.Duration) error
- func (s *Store) Purge(ctx context.Context) (int64, error)
Constants ¶
const Retention = 2 * 365 * 24 * time.Hour
Retention is how long rows are kept.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
Actor uuid.UUID
Action string // e.g. "user.set_role", "flag.kill_switch"
TargetType string // "user", "flag", "settings", "signup_request", ...
TargetID string
TargetUser uuid.UUID // uuid.Nil when the action is not about a user
Details map[string]any
IP string
}
Entry is one admin action about to happen.
type Filter ¶
type Filter struct {
Action string
Actor uuid.UUID
TargetUser uuid.UUID
Before int64 // return rows with id < Before (0 = from the newest)
Limit int
}
Filter narrows a listing.
type Row ¶
type Row struct {
ID int64 `json:"id"`
At time.Time `json:"at"`
Actor uuid.UUID `json:"actor_user_id"`
Action string `json:"action"`
TargetType string `json:"target_type"`
TargetID string `json:"target_id"`
TargetUser *uuid.UUID `json:"target_user_id,omitempty"`
Details map[string]any `json:"details"`
IP string `json:"ip"`
AccessEmail string `json:"access_email,omitempty"`
Outcome *string `json:"outcome"` // nil: in flight or unknown
Status *int `json:"status,omitempty"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
}
Row is a stored entry, as the listing returns it.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the Postgres side.
func (*Store) Begin ¶
Begin inserts the row for an action about to run and returns its id. An error means the action must not run.
func (*Store) NoteImpersonationStart ¶
func (s *Store) NoteImpersonationStart(ctx context.Context, admin, target uuid.UUID, ip string, window time.Duration) error
NoteImpersonationStart records that admin began viewing as target, once per pair per window (every impersonated request would otherwise add a row). A successful impersonation.stop ends the session: the next view-as of the same target logs a fresh start, so a stop is never left without its start.