retention

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package retention implements data-retention pruning for Legant's operational tables. Expired sessions, used/expired email and registration tokens, terminal or expired org invitations, the Fosite OAuth token stores (access/refresh/auth-code/PKCE/OIDC-session), expired agent tokens and API keys, delegation tokens dead past a grace window, and aged-out audit events accumulate indefinitely otherwise. The prune is safe to run repeatedly (idempotent) and is exposed both as the `legant maintenance prune` command and for scheduling as a Kubernetes CronJob.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPolicy = Policy{TokenGrace: 30 * 24 * time.Hour, AuditRetention: 0}

DefaultPolicy keeps dead tokens for 30 days and never auto-deletes audit.

Functions

This section is empty.

Types

type Policy

type Policy struct {
	// TokenGrace is how long a delegation token is kept after it expires before
	// being purged. A short grace keeps revocation/introspection answers correct
	// for recently-expired tokens; the row is dead weight after that.
	TokenGrace time.Duration
	// AuditRetention is the age beyond which audit_events are deleted. Zero keeps
	// audit events forever (the safe default for compliance).
	AuditRetention time.Duration
}

Policy controls the time-based windows. Durations of zero disable the corresponding age-based purge (expired-row cleanups always run).

type Result

type Result struct {
	ExpiredSessions     int64
	StaleEmailTokens    int64
	ExhaustedDCRTokens  int64
	StaleInvitations    int64
	DeadExchangedTokens int64
	ExpiredOAuthTokens  int64 // sum across the Fosite token tables
	ExpiredAgentTokens  int64
	ExpiredAPIKeys      int64
	AgedAuditEvents     int64
}

Result reports how many rows each step removed (or would remove, in dry-run).

func Prune

func Prune(ctx context.Context, pool *pgxpool.Pool, policy Policy, dryRun bool) (Result, error)

Prune removes (or, when dryRun, counts) prunable rows according to the policy. Each step is independent; a failure returns the partial result gathered so far alongside the error.

func (Result) Total

func (r Result) Total() int64

Total returns the sum of all pruned rows.

Jump to

Keyboard shortcuts

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