feat(audit,approvals,deliveries): wire audit producers, ITSM change requests, and fix Dockerfile.archie (#2153)
This commit is contained in:
26 files changed
+671
-35
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package judgement
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
_ "embed" // the starter policy sets
|
||||
"encoding/json/jsontext"
|
||||
@@ -22,6 +23,7 @@ import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/platform/httpapi"
|
||||
"github.com/samcharles93/archie-core/modules/audit"
|
||||
"github.com/samcharles93/archie-core/modules/connectors"
|
||||
"github.com/samcharles93/archie-core/modules/governance"
|
||||
"github.com/samcharles93/archie-core/modules/judgement/internal/store"
|
||||
@@ -61,6 +63,7 @@ type policyStore interface {
|
||||
type Policies struct {
|
||||
orgID string
|
||||
store policyStore
|
||||
audit audit.Recorder
|
||||
log *slog.Logger
|
||||
now func() time.Time
|
||||
}
|
||||
@@ -70,6 +73,9 @@ func NewPolicies(db *sqlx.DB, log *slog.Logger, orgID string) *Policies {
|
||||
return &Policies{orgID: orgID, store: store.New(db), log: log, now: time.Now}
|
||||
}
|
||||
|
||||
// UseAudit configures the audit recorder notified on policy updates.
|
||||
func (p *Policies) UseAudit(r audit.Recorder) { p.audit = r }
|
||||
|
||||
var starters = map[string]string{KindHardRules: starterHardRules, KindChangeRequest: starterChangeRequest}
|
||||
|
||||
// current returns the version of a kind in force, seeding the starter set the
|
||||
@@ -374,9 +380,19 @@ func (p *Policies) Put(ctx context.Context, kind, body, by string) (PolicySetVie
|
||||
if _, err := p.current(ctx, kind); err != nil {
|
||||
return PolicySetView{}, err
|
||||
}
|
||||
if _, err := p.store.AddPolicy(ctx, store.PolicySet{ID: uuid.New(), OrgID: p.orgID, Kind: kind, Body: body, CreatedBy: by}); err != nil {
|
||||
saved, err := p.store.AddPolicy(ctx, store.PolicySet{ID: uuid.New(), OrgID: p.orgID, Kind: kind, Body: body, CreatedBy: by})
|
||||
if err != nil {
|
||||
return PolicySetView{}, err
|
||||
}
|
||||
audit.Emit(ctx, p.audit, p.log, audit.Event{
|
||||
Category: "policy",
|
||||
Action: "policy.judgement.update",
|
||||
ActorID: cmp.Or(by, string(governance.SystemID)),
|
||||
ResourceKind: "judgement_policy",
|
||||
ResourceID: kind,
|
||||
Outcome: "success",
|
||||
Detail: map[string]any{"version": saved.Version},
|
||||
})
|
||||
return p.View(ctx, kind, 0)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user