Documentation
¶
Overview ¶
Package workflow runs tracked work through a workflow template that is data (ADR-0021). A template lists stages and the transitions between them; the engine checks a transition against the template, the caller and the state of the work, and enforces the rules a template cannot switch off: a stage marked verified is entered only on the product's own verification, a stage marked approved only by a different signed-in person, an exception only with a reason and an end date, and nothing is marked done while a prerequisite is unfinished.
The package is pure: no store, no network, no clock of its own.
Index ¶
- Constants
- func Baseline(marker string) bool
- func Finished(marker string) bool
- func IsBuiltIn(id string) bool
- type Actor
- type Refusal
- type Request
- type Stage
- type State
- type Template
- func (t *Template) Applies(subject string) bool
- func (t *Template) Check(st State, req Request, act Actor, now time.Time, verify func() Verification) (Transition, Stage, *Verification, error)
- func (t *Template) From(stage string) []Transition
- func (t *Template) Initial() Stage
- func (t *Template) Stage(id string) (Stage, bool)
- func (t *Template) Transition(id string) (Transition, bool)
- func (t *Template) Validate() error
- func (t *Template) Verifies() bool
- type Transition
- type Verification
Constants ¶
const ( Verified = "verified" // the evidence shows the change in effect NotVerified = "not-verified" // the evidence shows it is not Waiting = "waiting" // there is no evidence yet (no scan since the change, or an incomplete one) NotVerifiable = "not-verifiable" // the product cannot observe this subject the way it would need to )
Verification statuses: what the product's own evidence says about a change (ADR-0021 §5).
const ( RefuseUnknown = "unknown-transition" RefuseStage = "wrong-stage" RefuseRole = "role" RefuseApproval = "approval" RefuseField = "missing-field" RefuseUntil = "until" RefuseBlocked = "blocked" RefuseNotVerified = "not-verified" )
Refusal codes.
const ( MarkRequested = "requested" // the work exists; nothing has been decided or changed MarkApproved = "approved" // a second person approved the change MarkExecuted = "executed" // the change was made (the verification baseline) MarkReported = "reported" // the change was reported successful by whoever made it (also a baseline) MarkVerified = "verified" // the product's own evidence shows the change in effect MarkComplete = "complete" // closed as done (verified or not) MarkException = "exception" // a risk accepted until a date MarkCancelled = "cancelled" // closed as not done )
Markers: what a stage means, whatever it is called. Lists and metrics read markers, never stage names.
const ( SubjectFinding = "finding" // one finding on one endpoint or host SubjectCertificate = "certificate" // one certificate, by SHA-256 fingerprint SubjectReadiness = "readiness" // an endpoint that should reach a readiness level SubjectEndpoint = "endpoint" // an endpoint, with no measurable target SubjectSystem = "system" // a system )
Subject kinds: what a piece of work is about.
const ( RoleAnalyst = "analyst" RoleAdmin = "admin" )
Roles a transition may require. A viewer never changes anything (the server refuses it before this package is asked).
const ( FieldNote = "note" // why, in words FieldEvidence = "evidence" // a reference: a change ticket, a log, a link FieldUntil = "until" // an end date (an exception's) )
Fields a transition may require from the caller.
const ( MaxStages = 20 MaxTransitions = 60 MaxBytes = 64 << 10 )
Limits on a template's size.
const MaxException = 366 * 24 * time.Hour
MaxException is the longest an accepted risk or a wait may run before someone looks at it again.
Variables ¶
This section is empty.
Functions ¶
func Baseline ¶
Baseline says whether entering a stage with this marker resets the verification baseline.
Types ¶
type Actor ¶
type Actor struct {
Name string
Role string // admin, analyst, viewer
// Person is true for a signed-in account; false for the anonymous local operator and the
// automation token, which cannot be told apart from anyone else using them.
Person bool
}
Actor is who asks for a transition.
type Refusal ¶
Refusal is why a transition was not made. Code is stable for clients; Message is for people.
type Stage ¶
type Stage struct {
ID string `json:"id"`
Label string `json:"label"`
Marker string `json:"marker,omitempty"`
Terminal bool `json:"terminal,omitempty"`
}
Stage is one place work can be.
type State ¶
type State struct {
Stage string
CreatedBy string
Approvers []string
// Unfinished lists the prerequisites that are neither verified, complete nor cancelled.
Unfinished []int64
}
State is what the engine needs to know about a piece of work.
type Template ¶
type Template struct {
ID string `json:"id"`
Version int `json:"version"`
Title string `json:"title"`
Purpose string `json:"purpose"`
Subjects []string `json:"subjects"`
// Target is the readiness level the workflow is for (3: hybrid key exchange, 4: a post-quantum
// certificate); work under it cannot aim lower. 0 for workflows with no level.
Target int `json:"target,omitempty"`
Stages []Stage `json:"stages"`
Transitions []Transition `json:"transitions"`
}
Template is a workflow: its stages (the first is where work starts) and its transitions.
func BuiltIn ¶
func BuiltIn() []*Template
BuiltIn lists the built-in templates, sorted by id. It panics if one is invalid, which a test rules out.
func BuiltInByID ¶
BuiltInByID returns a built-in template.
func (*Template) Check ¶
func (t *Template) Check(st State, req Request, act Actor, now time.Time, verify func() Verification) (Transition, Stage, *Verification, error)
Check decides whether req may be applied to work in state st by act, at now. verify is called only when the transition needs verification, and its result is returned so the caller can record it. It returns the transition and the stage it enters.
func (*Template) From ¶
func (t *Template) From(stage string) []Transition
From lists the transitions that leave a stage, in template order.
func (*Template) Transition ¶
func (t *Template) Transition(id string) (Transition, bool)
Transition returns the transition with this id.
type Transition ¶
type Transition struct {
ID string `json:"id"`
Label string `json:"label"`
From []string `json:"from"`
To string `json:"to"`
// Role is the least role that may make it: analyst (the default) or admin.
Role string `json:"role,omitempty"`
// Require lists the fields the caller must give: note, evidence, until.
Require []string `json:"require,omitempty"`
// Approval makes it an approval: a signed-in person who did not request the work and has not
// approved it already.
Approval bool `json:"approval,omitempty"`
// Verify allows it only when the product's own verification says verified.
Verify bool `json:"verify,omitempty"`
}
Transition moves work from one of From to To.
type Verification ¶
type Verification struct {
Status string `json:"status"`
Detail string `json:"detail"`
At time.Time `json:"at"`
// CheckedAt is when the scan it rests on finished (the latest one, when there are several).
CheckedAt *time.Time `json:"checkedAt,omitempty"`
// Since is the baseline: the moment the change was recorded as made.
Since *time.Time `json:"since,omitempty"`
// Evidence names the scans or uploads it read, e.g. "scan 42".
Evidence []string `json:"evidence,omitempty"`
}
Verification is the product's answer, with what it rests on.