The delivery repository's contracts and SDK live under modules/ as mesh-delivery-contracts and mesh-delivery-sdk, their Go module paths renamed to match the folders (the TypeScript names already did), and every importer in mesh-delivery, mesh-catalog, mesh-host, mesh-tools and mesh-sdk follows in the same group: a design as it should be, one path per module, checked by the group's check building every importer. Builds: design 47 G §427, §88 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
114 lines
3.5 KiB
Go
114 lines
3.5 KiB
Go
package index
|
|
|
|
import (
|
|
"encoding/json"
|
|
"slices"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
)
|
|
|
|
// ConfigReadersTool is the indexer's tool that says who reads a module's config keys (design 32 *A value no longer
|
|
// read*): mesh-config asks it on each manifest-accepted, and a key no manifest on any trunk or open pull request reads
|
|
// any more is a retiring value.
|
|
const ConfigReadersTool = "indexer_config_readers"
|
|
|
|
// The kinds of a config key.
|
|
const (
|
|
ConfigKindValue = "value"
|
|
ConfigKindSecret = "secret"
|
|
)
|
|
|
|
// ConfigReaderRow is one key of a module's config: its kind (a value, or one of its own secrets) and who reads it now —
|
|
// the module itself where its trunk's manifest declares it, and each open pull request (owner/repository#number) whose
|
|
// head declares it. Nodes is left out: which nodes' applied builds read a key is the node-engines' word, not the
|
|
// indexer's, so mesh-config reads it there (an empty list would say "no node", which the indexer cannot know).
|
|
type ConfigReaderRow struct {
|
|
Module string `json:"module"`
|
|
Key string `json:"key"`
|
|
Kind string `json:"kind"`
|
|
Readers []string `json:"readers"`
|
|
Nodes []string `json:"nodes,omitempty"`
|
|
}
|
|
|
|
// configKeys are a manifest's config value keys (its `config` or `settings`) and its own secrets' names.
|
|
func configKeys(raw string) (values, secrets []string) {
|
|
if d, err := DeclarationsOf(raw); err == nil {
|
|
for k := range d {
|
|
values = append(values, k)
|
|
}
|
|
}
|
|
var m struct {
|
|
OwnSecrets map[string]json.RawMessage `json:"own-secrets"`
|
|
}
|
|
if json.Unmarshal([]byte(raw), &m) == nil {
|
|
for k := range m.OwnSecrets {
|
|
secrets = append(secrets, k)
|
|
}
|
|
}
|
|
return values, secrets
|
|
}
|
|
|
|
// ConfigReaders are the rows of module's config keys: every key any manifest of the module the indexer keeps ever
|
|
// declared (so a key no manifest declares any more is a row with no reader), each with who reads it now. trunk is the
|
|
// modules state, manifests the manifests state by digest, candidates the open pull requests' config declarations.
|
|
func ConfigReaders(module string, trunk map[string]meshcatalog.ModulesByModuleValue, manifests map[string]meshcatalog.ManifestsByDigestValue, candidates []meshcatalog.ConfigCandidatesByPullValue) []ConfigReaderRow {
|
|
rows := map[string]*ConfigReaderRow{}
|
|
add := func(kind, key, reader string) {
|
|
id := kind + "|" + key
|
|
r := rows[id]
|
|
if r == nil {
|
|
r = &ConfigReaderRow{Module: module, Key: key, Kind: kind, Readers: []string{}}
|
|
rows[id] = r
|
|
}
|
|
if reader != "" && !slices.Contains(r.Readers, reader) {
|
|
r.Readers = append(r.Readers, reader)
|
|
}
|
|
}
|
|
current := ""
|
|
if m, ok := trunk[module]; ok {
|
|
current = m.Manifest
|
|
}
|
|
for digest, kept := range manifests {
|
|
if kept.Module != module {
|
|
continue
|
|
}
|
|
reader := ""
|
|
if digest == current {
|
|
reader = module
|
|
}
|
|
values, secrets := configKeys(kept.Manifest)
|
|
for _, k := range values {
|
|
add(ConfigKindValue, k, reader)
|
|
}
|
|
for _, k := range secrets {
|
|
add(ConfigKindSecret, k, reader)
|
|
}
|
|
}
|
|
for _, c := range candidates {
|
|
for key := range c.Declares[module] {
|
|
add(ConfigKindValue, key, c.Pull)
|
|
}
|
|
}
|
|
out := make([]ConfigReaderRow, 0, len(rows))
|
|
for _, r := range rows {
|
|
slices.Sort(r.Readers)
|
|
out = append(out, *r)
|
|
}
|
|
slices.SortFunc(out, func(a, b ConfigReaderRow) int {
|
|
if a.Kind != b.Kind {
|
|
if a.Kind < b.Kind {
|
|
return -1
|
|
}
|
|
return 1
|
|
}
|
|
if a.Key < b.Key {
|
|
return -1
|
|
}
|
|
if a.Key > b.Key {
|
|
return 1
|
|
}
|
|
return 0
|
|
})
|
|
return out
|
|
}
|