workflow

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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).

View Source
const (
	RefuseUnknown     = "unknown-transition"
	RefuseStage       = "wrong-stage"
	RefuseRole        = "role"
	RefuseApproval    = "approval"
	RefuseField       = "missing-field"
	RefuseUntil       = "until"
	RefuseBlocked     = "blocked"
	RefuseNotVerified = "not-verified"
)

Refusal codes.

View Source
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.

View Source
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.

View Source
const (
	RoleAnalyst = "analyst"
	RoleAdmin   = "admin"
)

Roles a transition may require. A viewer never changes anything (the server refuses it before this package is asked).

View Source
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.

View Source
const (
	MaxStages      = 20
	MaxTransitions = 60
	MaxBytes       = 64 << 10
)

Limits on a template's size.

View Source
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

func Baseline(marker string) bool

Baseline says whether entering a stage with this marker resets the verification baseline.

func Finished

func Finished(marker string) bool

Finished says whether a stage marker counts as finished for the work that depends on it.

func IsBuiltIn

func IsBuiltIn(id string) bool

IsBuiltIn says whether an id belongs to a built-in template (which a custom template may not replace).

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

type Refusal struct {
	Code    string
	Message string
}

Refusal is why a transition was not made. Code is stable for clients; Message is for people.

func (*Refusal) Error

func (r *Refusal) Error() string

type Request

type Request struct {
	Transition string
	Note       string
	Evidence   string
	Until      *time.Time
}

Request is a transition the caller asks for, with the fields they gave.

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

func BuiltInByID(id string) (*Template, bool)

BuiltInByID returns a built-in template.

func Parse

func Parse(b []byte) (*Template, error)

Parse reads a template strictly (unknown fields are refused) and validates it.

func (*Template) Applies

func (t *Template) Applies(subject string) bool

Applies says whether the template may be used for a subject kind.

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) Initial

func (t *Template) Initial() Stage

Initial is the stage new work starts in.

func (*Template) Stage

func (t *Template) Stage(id string) (Stage, bool)

Stage returns the stage with this id.

func (*Template) Transition

func (t *Template) Transition(id string) (Transition, bool)

Transition returns the transition with this id.

func (*Template) Validate

func (t *Template) Validate() error

Validate checks the template against every rule of ADR-0021 and returns all the problems found.

func (*Template) Verifies

func (t *Template) Verifies() bool

Verifies says whether any transition of the template needs verification.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL