refactor(archie): build the policy sets in their own constructor so Run stays within its statement limit

This commit is contained in:
sam committed 2026-11-16 09:40:26 +11:00
1 parent ef62dcc97a
commit 0c8b673615
1 file changed
+10 -4
+10 -4
View File
@@ -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 {