H-20: a tools bundle's words hold its module's want fingerprint
Builds: design 47 G §519, §618
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
||||
@@ -239,6 +240,9 @@ func Split(node string, resources []json.RawMessage, fps map[string]string, fill
|
||||
if raw, err = withFingerprint(raw, head.Type, fps[head.Module]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if raw, err = withBundleFingerprints(raw, head.Type, fps); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c := out[key]
|
||||
c.Resources = append(c.Resources, raw)
|
||||
@@ -286,3 +290,62 @@ func withFingerprint(raw json.RawMessage, kind, fp string) (json.RawMessage, err
|
||||
fields["env"] = body
|
||||
return json.Marshal(fields)
|
||||
}
|
||||
|
||||
// withBundleFingerprints is raw, when it is a process whose env hands tools bundles their words (catalogue.RuntimeToolEnv),
|
||||
// with each module's words holding FingerprintVar set to that module's fingerprint in fps: a bundle reads the fingerprint of
|
||||
// its own module's want from the environment the tool runner starts it with (design 47 G §519). A module fps names no
|
||||
// fingerprint for keeps its words, and the runner's own fingerprint reaches no bundle but its own module's (§618).
|
||||
func withBundleFingerprints(raw json.RawMessage, kind string, fps map[string]string) (json.RawMessage, error) {
|
||||
if kind != string(declaration.TypeProcess) {
|
||||
return raw, nil
|
||||
}
|
||||
var fields map[string]json.RawMessage
|
||||
if err := json.Unmarshal(raw, &fields); err != nil {
|
||||
return nil, fmt.Errorf("compositions: a %s resource is not JSON: %w", kind, err)
|
||||
}
|
||||
var env map[string]string
|
||||
if had, ok := fields["env"]; !ok || json.Unmarshal(had, &env) != nil || env[catalogue.RuntimeToolModules] == "" {
|
||||
return raw, nil
|
||||
}
|
||||
given := map[string]map[string]string{}
|
||||
if had := env[catalogue.RuntimeToolEnv]; had != "" {
|
||||
if err := json.Unmarshal([]byte(had), &given); err != nil {
|
||||
return nil, fmt.Errorf("compositions: the %s of a process is not words by module: %w", catalogue.RuntimeToolEnv, err)
|
||||
}
|
||||
}
|
||||
for module, words := range given {
|
||||
if fp := fps[module]; fp != "" {
|
||||
if words == nil {
|
||||
words = map[string]string{}
|
||||
given[module] = words
|
||||
}
|
||||
words[FingerprintVar] = fp
|
||||
}
|
||||
}
|
||||
for module, fp := range fps { // a module with bundles and no words of its own still reads its fingerprint
|
||||
if _, has := given[module]; !has && fp != "" && hasLoadedBundle(env, module) {
|
||||
given[module] = map[string]string{FingerprintVar: fp}
|
||||
}
|
||||
}
|
||||
body, err := json.Marshal(given)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
env[catalogue.RuntimeToolEnv] = string(body)
|
||||
envBody, err := json.Marshal(env)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fields["env"] = envBody
|
||||
return json.Marshal(fields)
|
||||
}
|
||||
|
||||
// hasLoadedBundle is whether the runtime's served list (catalogue.RuntimeToolModules, `module=path` entries) names a bundle of module.
|
||||
func hasLoadedBundle(env map[string]string, module string) bool {
|
||||
for _, entry := range strings.Split(env[catalogue.RuntimeToolModules], ",") {
|
||||
if strings.HasPrefix(entry, module+"=") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user