46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
)
|
|
|
|
// WorkflowDraftsKind holds unpublished edits to workflows. A draft may be
|
|
// incomplete or invalid, so only its shape is checked; publishing copies it
|
|
// into workflow-definitions, which validates it. Nothing runs from a draft
|
|
// except an explicit test run.
|
|
const WorkflowDraftsKind = "workflow-drafts"
|
|
|
|
type workflowDraft struct {
|
|
ID string `json:"id"`
|
|
YAML string `json:"yaml"`
|
|
}
|
|
|
|
type workflowDraftCollection struct {
|
|
Drafts []workflowDraft `json:"drafts"`
|
|
}
|
|
|
|
func workflowDraftsDefinition() Definition {
|
|
return Definition{
|
|
Kind: WorkflowDraftsKind,
|
|
Title: "Workflow drafts",
|
|
Document: workflowDraftCollection{},
|
|
ApplyMode: "live",
|
|
Seed: func(config.Config) any { return workflowDraftCollection{Drafts: []workflowDraft{}} },
|
|
Validate: func(input []byte) error {
|
|
return validateAs(input, func(c workflowDraftCollection) error {
|
|
seen := map[string]bool{}
|
|
for _, draft := range c.Drafts {
|
|
if strings.TrimSpace(draft.ID) == "" || seen[draft.ID] {
|
|
return fmt.Errorf("workflow draft id %q is empty or repeated", draft.ID)
|
|
}
|
|
seen[draft.ID] = true
|
|
}
|
|
return nil
|
|
})
|
|
},
|
|
}
|
|
}
|