From 0c8b673615c510573f38212b89217e57c1b5f7eb Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 16 Nov 2026 09:40:26 +1100 Subject: [PATCH] refactor(archie): build the policy sets in their own constructor so Run stays within its statement limit --- internal/app/archie/run.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/app/archie/run.go b/internal/app/archie/run.go index 636c1b691..b63036b17 100644 --- a/internal/app/archie/run.go +++ b/internal/app/archie/run.go @@ -93,14 +93,12 @@ func Run(ctx context.Context, configPath string) error { allow := approvals.NewModule(db, log.With("module", "approvals"), orgID, tell, engine, classes, settings, settings) allow.Routes(mux, guard) classes.Routes(mux, guard, allow) - policies := judgement.NewPolicies(db, log.With("module", "judgement"), orgID) - policies.Routes(mux, guard) + policies := newPolicies(db, log, mux, guard) // An answer a channel delivers is an event, and settles its request. hear := events.NewModule(db, log.With("module", "events"), orgID, conns, engine, allow) hear.Routes(mux, guard) judge := newJudgement(db, log, conns, classes, policies, settings, hear) - remembered := memory.NewModule(db, orgID) - engine.Register("investigate", 1, runs.Investigate(settings, conns, judge, allow, tell, remembered)) //nolint:contextcheck // see above + engine.Register("investigate", 1, runs.Investigate(settings, conns, judge, allow, tell, memory.NewModule(db, orgID))) //nolint:contextcheck // see above engine.Routes(mux, guard, orgID, hear, judge, allow) dashboard.Routes(mux, ui.DistDirFS) @@ -124,6 +122,14 @@ func work(ctx context.Context, loops ...func(context.Context)) func() { return workers.Wait } +// newPolicies returns the hard rules and change-request rules, with their +// routes. +func newPolicies(db *sqlx.DB, log *slog.Logger, mux *http.ServeMux, guard func(http.Handler) http.Handler) *judgement.Policies { + policies := judgement.NewPolicies(db, log.With("module", "judgement"), orgID) + policies.Routes(mux, guard) + return policies +} + // newJudgement returns the judgement module with its hard rules, data guards // and change-request rules. A failed action tightens its class. func newJudgement(db *sqlx.DB, log *slog.Logger, conns *connectors.Module, classes *judgement.Classes, policies *judgement.Policies, settings *governance.Module, heard judgement.Events) *judgement.Module {