Files
archie/internal/app/statestore/denial_retention.go
T
sam 003771ca48 feat(access): denial retention knob, State Store sweep and dashboard denials page (#1842)
Add [access].denial_retention (default 90 days, matching the audit-retention
seed) wired through config defaults and validation; the State Store sweeps
denial records older than the configured age hourly via the new
access.DenialPruner / PruneDenials store query. The dashboard gains
GET /api/access/denials (read_audit-gated, so org admins/owners see their
org's records; the store scopes by the credential's org) and an
/org/denials page backed by a Pinia store.
2026-10-31 14:23:31 +11:00

45 lines
1.1 KiB
Go

package statestore
import (
"context"
"time"
"github.com/samcharles93/archie-core/internal/domain/access"
)
// denialSweepInterval is how often the configured denial retention is applied.
const denialSweepInterval = time.Hour
// sweepDenials deletes denial records older than the configured
// access.denial_retention until ctx ends. A non-positive retention keeps the
// records forever, so the sweep does not run at all in that case.
func (b *server) sweepDenials(ctx context.Context) {
pruner, ok := b.st.(access.DenialPruner)
if !ok {
return
}
retention := b.cfg.Access.DenialRetention.Std()
if retention <= 0 {
return
}
ticker := time.NewTicker(denialSweepInterval)
defer ticker.Stop()
for {
cutoff := time.Now().Add(-retention)
rows, err := pruner.PruneDenials(ctx, cutoff)
switch {
case err != nil:
if ctx.Err() == nil {
b.log.WarnContext(ctx, "prune access denials", "err", err)
}
case rows > 0:
b.log.InfoContext(ctx, "pruned access denials", "rows", rows, "cutoff", cutoff.UTC())
}
select {
case <-ctx.Done():
return
case <-ticker.C:
}
}
}