Twelve definitions each advertised a bare {"type":"object"} or {"type":"array"},
so no resource descriptor carried a single field: the Web UI had nothing to
label, describe or format a field with, and the one component that parsed a
schema was dead code. The constants could not be kept honest either -- a schema
written beside a struct drifts the moment a field is added, and nothing compares
the two.
Definition now names its document type and Descriptor derives the schema from it.
json tags give the keys, falling back to the Go field name because that is what
encoding/json stores; the Go type gives type and format; and a field's own
title, format and doc tags override. A duration is a string with format
"duration", which is how every duration field in the catalogue -- poll_interval,
max_uptime, rate_limit.window -- gets a client-side affordance from one rule
instead of twelve hand-written ones.
Deliberately structural: it emits no prose of its own. Field descriptions already
have one home (internal/webui/config_schema.go, keyed by dotted config path), and
a second would be two places to keep the same fact true. It also never emits
"required", because an empty string is legitimate for nearly every field here --
a blank workspace, a disabled rate limit -- so requiring most of them would
invite a client to enforce something the document does not mean.
Guarded by TestEveryResourceDescriptorDerivesProperties, which walks the catalogue
the production constructor builds and fails if any kind describes no fields --
the assertion that would have caught all twelve. It accepts a keyed collection's
additionalProperties as described, because a map document has no fixed keys.
Verified: controlplane, workflow, webui, archieui and staterpc suites, go vet,
go build ./..., golangci-lint run ./... (0 issues), docs:check.
55 lines
2.0 KiB
Go
55 lines
2.0 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
)
|
|
|
|
const WorkflowDefinitionsKind = "workflow-definitions"
|
|
|
|
// stepRegistry is this package's single resolution site for the workflow step
|
|
// vocabulary, and the guard on the manager it must be handed. The manager is
|
|
// built at the composition root (infrastructure/workflowsteps.NewManager) and
|
|
// injected, so the State Store server -- the validating side -- and the
|
|
// workflow-definitions client both resolve the vocabulary that composition
|
|
// root registered. Agreement is within one build: the State Store and
|
|
// archie-agent are separately deployed binaries, so a State Store built from
|
|
// newer source than the agent it dispatches to can still disagree, and only a
|
|
// matching deploy fixes that.
|
|
func stepRegistry(steps *workflow.Manager) (workflow.StepRegistry, error) {
|
|
if steps == nil {
|
|
return nil, errors.New("control plane: no workflow step vocabulary: the composition root must register the provider set (infrastructure/workflowsteps.NewManager) before the first resolution")
|
|
}
|
|
return steps.Registry(), nil
|
|
}
|
|
|
|
func workflowDefinitionsDefinition(steps workflow.StepRegistry) Definition {
|
|
return Definition{
|
|
Kind: WorkflowDefinitionsKind,
|
|
Title: "Workflow definitions",
|
|
Document: workflow.WorkflowDefinitionCollection{},
|
|
ApplyMode: "live",
|
|
Seed: func(config.Config) any {
|
|
return workflow.ShippedDefinitions()
|
|
},
|
|
Defaults: func() any {
|
|
return workflow.ShippedDefinitions()
|
|
},
|
|
Validate: func(input []byte) error {
|
|
_, err := workflow.DecodeDefinitionCollection(input, steps)
|
|
return err
|
|
},
|
|
}
|
|
}
|
|
|
|
func encodeWorkflowDefinitions(collection workflow.WorkflowDefinitionCollection, steps workflow.StepRegistry) ([]byte, error) {
|
|
if err := workflow.ValidateDefinitionCollection(collection, steps); err != nil {
|
|
return nil, fmt.Errorf("%w: %w", ErrValidation, err)
|
|
}
|
|
return json.Marshal(collection)
|
|
}
|