Documentation
¶
Overview ¶
Package retention is the data-lifecycle layer (roadmap E2): a generalized legal hold over any entity (not just documents) and a Data Subject Request ledger (export/erasure) with a statutory-override reason. Per-record-class disposition over product tables is orchestrated by the scheduler with product-supplied callbacks; these are the concrete, framework-owned primitives a compliance product would otherwise hand-roll. All operations run in the caller's tenant transaction (RLS-scoped).
Index ¶
- type DSR
- func (d *DSR) Complete(ctx context.Context, db database.TenantDB, id uuid.UUID) error
- func (d *DSR) Get(ctx context.Context, db database.TenantDB, id uuid.UUID) (Request, error)
- func (d *DSR) Open(ctx context.Context, db database.TenantDB, subjectRef string, kind Kind) (uuid.UUID, error)
- func (d *DSR) Reject(ctx context.Context, db database.TenantDB, id uuid.UUID, overrideReason string) error
- type DisposeFunc
- type Engine
- func (e *Engine) RunErasure(ctx context.Context, db database.TenantDB, requestID uuid.UUID) (int, error)
- func (e *Engine) RunExport(ctx context.Context, db database.TenantDB, requestID uuid.UUID) (map[string]any, error)
- func (e *Engine) SweepDisposition(ctx context.Context, db database.TenantDB, at time.Time) (int, error)
- type EraseFunc
- type ExportFunc
- type Hold
- type Holds
- func (h *Holds) IsHeld(ctx context.Context, db database.TenantDB, entityType string, ...) (bool, error)
- func (h *Holds) List(ctx context.Context, db database.TenantDB) ([]Hold, error)
- func (h *Holds) Place(ctx context.Context, db database.TenantDB, entityType string, ...) (uuid.UUID, error)
- func (h *Holds) Release(ctx context.Context, db database.TenantDB, id uuid.UUID) error
- type Kind
- type RecordClass
- type Registry
- type Request
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DSR ¶
type DSR struct {
// contains filtered or unexported fields
}
DSR is the Data Subject Request ledger (export / erasure). It tracks the request lifecycle and the statutory-override reason when an erasure is refused because a retention obligation (or a legal hold) forbids it. The actual data export/erasure is performed by product-registered callbacks per record class; this ledger is the auditable request record.
func (*DSR) Complete ¶
Complete marks a pending request fulfilled (after the product has performed the export/erasure). KindConflict if the request is not pending.
type DisposeFunc ¶
DisposeFunc disposes the class's records whose retention lapsed on/before `before` — deleting or anonymizing them — and returns how many. It must itself skip records under legal hold (consult Holds.IsHeld). Runs in the caller's tenant transaction.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates disposition and DSR fulfilment over the registered classes.
func (*Engine) RunErasure ¶
func (e *Engine) RunErasure(ctx context.Context, db database.TenantDB, requestID uuid.UUID) (int, error)
RunErasure fulfils a pending erasure DSR: it invokes each class's Erase for the subject and marks the request completed, returning the total records affected. A legal hold that forbids erasure must be enforced by the product's Erase callback (skip held records) or by rejecting the DSR first with a reason.
func (*Engine) RunExport ¶
func (e *Engine) RunExport(ctx context.Context, db database.TenantDB, requestID uuid.UUID) (map[string]any, error)
RunExport fulfils a pending export DSR: it invokes each class's Export for the subject, aggregates the results by class key, marks the request completed, and returns the payload. All work is in the caller's tenant tx, so a failure leaves the request pending and rolls back partial exports.
func (*Engine) SweepDisposition ¶
func (e *Engine) SweepDisposition(ctx context.Context, db database.TenantDB, at time.Time) (int, error)
SweepDisposition runs each class's Dispose for records whose retention lapsed by `at`, in the caller's tenant transaction, returning the total disposed. Classes without a Dispose callback are skipped. Intended to be driven periodically by the scheduler.
type EraseFunc ¶
EraseFunc erases (or anonymizes) the class's data for a DSR subject and returns how many records were affected. Runs in the caller's tenant transaction.
type ExportFunc ¶
type ExportFunc func(ctx context.Context, db database.TenantDB, subjectRef string) (map[string]any, error)
ExportFunc returns the class's data for a DSR subject (for a data-portability export). Runs in the caller's tenant transaction.
type Holds ¶
type Holds struct {
// contains filtered or unexported fields
}
Holds manages generalized legal holds. A hold on (entityType, entityID) blocks disposition of that entity until released — retention sweeps consult IsHeld.
func (*Holds) IsHeld ¶
func (h *Holds) IsHeld(ctx context.Context, db database.TenantDB, entityType string, entityID uuid.UUID) (bool, error)
IsHeld reports whether the entity has an active legal hold.
func (*Holds) Place ¶
func (h *Holds) Place(ctx context.Context, db database.TenantDB, entityType string, entityID uuid.UUID, reason string) (uuid.UUID, error)
Place puts an entity under legal hold. Reason is required. A second active hold on the same entity is a KindConflict (there is at most one active hold).
type RecordClass ¶
type RecordClass struct {
Key string
Retention time.Duration // documentary; the Dispose callback enforces it
Dispose DisposeFunc
Export ExportFunc
Erase EraseFunc
}
RecordClass declares one class of product data and how to dispose/export/erase it. Any callback may be nil (a class with no Export contributes nothing to an export, etc.).
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the boot-time catalog of record classes.
func (*Registry) Register ¶
func (r *Registry) Register(c RecordClass)
Register adds a record class. Keys must be non-empty and unique; the first error is retained and surfaced by Err (checked at boot).