The Web UI and messaging channels now read and write Archie's runtime settings through one versioned, audited control-plane API hosted on the State Store's existing gRPC server: catalog, query, command, watch. Each feature owns its resource, validation and commands; storage only writes versions and audit records. Workflows move with it. Definitions become portable YAML compiled through a closed, typed step registry and stored as a control-plane resource, so the yaegi interpretation paths (internal/gate, wfeval, wfextract, gateeval, gateextract, skillbuild) are deleted rather than carried. The UI process reads definitions as data: the JSON projection lives in internal/domain/workflow/task so a dashboard decodes the stored collection without linking the workflow engine, which cmd/archie-ui's deletion gate forbids. Shipped definitions ride the catalog descriptor rather than a bespoke REST route, keeping the API to its four operations. archie-messaging gains -state-store-target/-state-store-token and reads channel settings from the database, failing closed when the State Store is unreachable: the database is authoritative for those settings.
90 lines
3.6 KiB
Go
90 lines
3.6 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
)
|
|
|
|
const (
|
|
RepositoryPoliciesKind = "repository-policies"
|
|
ChannelSettingsKind = "channel-settings"
|
|
SchedulingPolicyKind = "scheduling-policy"
|
|
ToolSettingsKind = "tool-settings"
|
|
PluginSettingsKind = "plugin-settings"
|
|
ContainerRuntimePoliciesKind = "container-runtime-policies"
|
|
)
|
|
|
|
type schedulingPolicy struct {
|
|
PollInterval string `json:"poll_interval"`
|
|
MaxRetries int `json:"max_retries"`
|
|
Dispatch config.Dispatch `json:"dispatch"`
|
|
}
|
|
|
|
type pluginSettings struct {
|
|
PluginDir string `json:"plugin_dir"`
|
|
ModuleDir string `json:"module_dir"`
|
|
SecretEngineDir string `json:"secret_engine_dir"`
|
|
SkillsDir string `json:"skills_dir"`
|
|
}
|
|
|
|
func operationalDefinitions() []Definition {
|
|
return []Definition{
|
|
{Kind: RepositoryPoliciesKind, Title: "Repository policies", ApplyMode: "restart-required", Schema: arraySchema, Seed: func(cfg config.Config) any { return cfg.Repos }, Validate: validateRepositories},
|
|
{Kind: ChannelSettingsKind, Title: "Channel settings", ApplyMode: "restart-required", Schema: objectSchema, Seed: seedChannels, Validate: validateChannels},
|
|
{Kind: SchedulingPolicyKind, Title: "Scheduling policy", ApplyMode: "restart-required", Schema: objectSchema, Seed: func(cfg config.Config) any {
|
|
return schedulingPolicy{cfg.PollInterval.Std().String(), cfg.MaxRetries, cfg.Dispatch}
|
|
}, Validate: validateScheduling},
|
|
{Kind: ToolSettingsKind, Title: "Tool and MCP settings", ApplyMode: "restart-required", Schema: objectSchema, Seed: seedTools, Validate: validateTools},
|
|
{Kind: PluginSettingsKind, Title: "Plugin settings", ApplyMode: "restart-required", Schema: objectSchema, Seed: func(cfg config.Config) any {
|
|
return pluginSettings{cfg.PluginDir, cfg.ModuleDir, cfg.SecretEngineDir, cfg.SkillsDir}
|
|
}, Validate: func(input []byte) error { return validateAs(input, func(pluginSettings) error { return nil }) }},
|
|
{Kind: ContainerRuntimePoliciesKind, Title: "Container runtime policies", ApplyMode: "restart-required", Schema: objectSchema, Seed: func(cfg config.Config) any { return cfg.Containers }, Validate: validateContainers},
|
|
}
|
|
}
|
|
|
|
func validateRepositories(input []byte) error {
|
|
return validateAs(input, func(repos []config.Repo) error {
|
|
seen := make(map[string]struct{}, len(repos))
|
|
for _, repo := range repos {
|
|
if strings.TrimSpace(repo.Owner) == "" || strings.TrimSpace(repo.Name) == "" {
|
|
return fmt.Errorf("repository owner and name are required")
|
|
}
|
|
if _, exists := seen[repo.FullName()]; exists {
|
|
return fmt.Errorf("duplicate repository %q", repo.FullName())
|
|
}
|
|
seen[repo.FullName()] = struct{}{}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func validateScheduling(input []byte) error {
|
|
return validateAs(input, func(policy schedulingPolicy) error {
|
|
if policy.MaxRetries < 0 {
|
|
return fmt.Errorf("max_retries must not be negative")
|
|
}
|
|
if policy.PollInterval != "0s" {
|
|
interval, err := time.ParseDuration(policy.PollInterval)
|
|
if err != nil || interval < 0 {
|
|
return fmt.Errorf("poll_interval must be a non-negative duration")
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func validateContainers(input []byte) error {
|
|
return validateAs(input, func(settings config.ContainerConfig) error {
|
|
if settings.MaxConcurrency < 0 || time.Duration(settings.MaxUptime) < 0 || time.Duration(settings.VolumeTTL) < 0 {
|
|
return fmt.Errorf("container limits must not be negative")
|
|
}
|
|
if settings.PullPolicy != "" && settings.PullPolicy != "missing" && settings.PullPolicy != "always" {
|
|
return fmt.Errorf("pull_policy must be missing or always")
|
|
}
|
|
return nil
|
|
})
|
|
}
|