diff --git a/go/seats/nodeengine/contract.go b/go/seats/nodeengine/contract.go index 17f22ec..2be3506 100644 --- a/go/seats/nodeengine/contract.go +++ b/go/seats/nodeengine/contract.go @@ -23,6 +23,7 @@ const ( VerbActs = "acts" VerbPackages = "packages" VerbComposition = "composition" + VerbCompositionDiff = "composition-diff" VerbCompose = "compose" VerbComposeCandidate = "compose-candidate" VerbManifestReads = "manifest-reads" @@ -49,7 +50,7 @@ const ( // Verbs is every verb the seat serves, in its definition's order: a new copy each call. func Verbs() []string { - return []string{VerbHandOver, VerbAccessAct, VerbJudgeDirectories, VerbSetuidSearch, VerbRootFree, VerbActs, VerbPackages, VerbComposition, VerbCompose, VerbComposeCandidate, VerbManifestReads, VerbApplyOrder, VerbSeatList, VerbSeatListAgain, VerbFirstViews, VerbFirstViewAgain, VerbEntryAgain, VerbProcessBuilds, VerbConverged} + return []string{VerbHandOver, VerbAccessAct, VerbJudgeDirectories, VerbSetuidSearch, VerbRootFree, VerbActs, VerbPackages, VerbComposition, VerbCompositionDiff, VerbCompose, VerbComposeCandidate, VerbManifestReads, VerbApplyOrder, VerbSeatList, VerbSeatListAgain, VerbFirstViews, VerbFirstViewAgain, VerbEntryAgain, VerbProcessBuilds, VerbConverged} } // Events is every event published on the seat's subject: a new copy each call. @@ -625,6 +626,26 @@ type Composed struct { V int64 `json:"v"` } +// CompositionDiffEntry is one entry that differs between the running composition and the other. +type CompositionDiffEntry struct { + // the value is a secret, so neither value is given + Masked bool `json:"masked,omitempty"` + // the entry: an environment entry by its name, else the part of the resource that differs + Name string `json:"name"` + // its value in the other composition; absent where the other lacks it or the value is a secret + Other string `json:"other,omitempty"` + // its value in the running composition; absent where the running one lacks it or the value is a secret + Running string `json:"running,omitempty"` +} + +// CompositionDiffResource is one resource with the entries of it that differ. +type CompositionDiffResource struct { + // the entries of the resource that differ + Entries []CompositionDiffEntry `json:"entries"` + // the resource, as the composition names it + Resource string `json:"resource"` +} + // DeclaredGroup is a group. type DeclaredGroup struct { Gid int64 `json:"gid"` @@ -1338,6 +1359,29 @@ type CompositionAnswer struct { WithheldUnknown string `json:"withheld-unknown,omitempty"` } +// CompositionDiffInput is what composition-diff takes. +type CompositionDiffInput struct { + // the digest (sha256:…) of the composition to compare with; give it or revision + Digest string `json:"digest,omitempty"` + // the module, as placed on this machine; node for the node's own + Module string `json:"module"` + // the revision of the module's composition key to compare with, from the revisions the bucket keeps; give it or digest + Revision int64 `json:"revision,omitempty"` +} + +// CompositionDiffAnswer is what composition-diff answers. +type CompositionDiffAnswer struct { + // the module + Module string `json:"module"` + // the node + Node string `json:"node"` + Other *Revision `json:"other,omitempty"` + // each resource with an entry that differs; empty when none differs + Resources []CompositionDiffResource `json:"resources"` + // the digest of the composition that runs; absent when nothing runs + Running string `json:"running,omitempty"` +} + // ComposeInput is what compose takes. type ComposeInput struct { // a module placed on this machine whose apply is also tried again (optional) diff --git a/go/seats/nodeengine/contract_test.go b/go/seats/nodeengine/contract_test.go index d8150dd..0e1072c 100644 --- a/go/seats/nodeengine/contract_test.go +++ b/go/seats/nodeengine/contract_test.go @@ -135,6 +135,12 @@ func TestFixtures(t *testing.T) { decode: func(b []byte) (any, error) { var v ConvergedAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, {name: "composition names the filter part kept because allowed did not answer", subject: "", given: "{\"composition\":{\"key\":\"\"},\"judged\":{\"judgement\":\"\",\"waits_for_yes\":false,\"words\":\"\"},\"module\":\"nftables\",\"node\":\"desk\",\"started\":true,\"withheld-parts\":[{\"part\":\"node-packet-filter.allowed\",\"why\":\"asked of the seat node-packet-filter's verb allowed on desk, which did not answer within 10s\"}]}", wire: "{\"composition\":{\"key\":\"\"},\"judged\":{\"judgement\":\"\",\"waits_for_yes\":false,\"words\":\"\"},\"module\":\"nftables\",\"node\":\"desk\",\"started\":true,\"withheld-parts\":[{\"part\":\"node-packet-filter.allowed\",\"why\":\"asked of the seat node-packet-filter's verb allowed on desk, which did not answer within 10s\"}]}", decode: func(b []byte) (any, error) { var v CompositionAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, + {name: "composition-diff asks a module against a digest", subject: "", given: "{\"digest\":\"sha256:aa\",\"module\":\"plex\"}", wire: "{\"digest\":\"sha256:aa\",\"module\":\"plex\"}", + decode: func(b []byte) (any, error) { var v CompositionDiffInput; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, + {name: "composition-diff answers the entries that differ per resource, a secret masked", subject: "", given: "{\"module\":\"plex\",\"node\":\"ace\",\"other\":{\"digest\":\"sha256:aa\",\"key\":\"plex\",\"revision\":12},\"resources\":[{\"entries\":[{\"name\":\"PLEX_LOG_LEVEL\",\"other\":\"debug\",\"running\":\"info\"},{\"masked\":true,\"name\":\"PLEX_TOKEN\"}],\"resource\":\"service:plex\"}],\"running\":\"sha256:bb\"}", wire: "{\"module\":\"plex\",\"node\":\"ace\",\"other\":{\"digest\":\"sha256:aa\",\"key\":\"plex\",\"revision\":12},\"resources\":[{\"entries\":[{\"name\":\"PLEX_LOG_LEVEL\",\"other\":\"debug\",\"running\":\"info\"},{\"masked\":true,\"name\":\"PLEX_TOKEN\"}],\"resource\":\"service:plex\"}],\"running\":\"sha256:bb\"}", + decode: func(b []byte) (any, error) { var v CompositionDiffAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, + {name: "composition-diff answers no resource when none differs", subject: "", given: "{\"module\":\"plex\",\"node\":\"ace\",\"resources\":[],\"running\":\"sha256:aa\"}", wire: "{\"module\":\"plex\",\"node\":\"ace\",\"resources\":[],\"running\":\"sha256:aa\"}", + decode: func(b []byte) (any, error) { var v CompositionDiffAnswer; err := json.Unmarshal(b, &v); return v, err }, subjectIs: nil}, } for _, c := range cases { v, err := c.decode([]byte(c.given)) diff --git a/seats/node-engine/fixtures/verbs.json b/seats/node-engine/fixtures/verbs.json index a495cb6..23dfb66 100644 --- a/seats/node-engine/fixtures/verbs.json +++ b/seats/node-engine/fixtures/verbs.json @@ -332,5 +332,53 @@ } ] } + }, + { + "name": "composition-diff asks a module against a digest", + "of": "verb:composition-diff.input", + "given": { + "module": "plex", + "digest": "sha256:aa" + } + }, + { + "name": "composition-diff answers the entries that differ per resource, a secret masked", + "of": "verb:composition-diff.answer", + "given": { + "node": "ace", + "module": "plex", + "running": "sha256:bb", + "other": { + "key": "plex", + "revision": 12, + "digest": "sha256:aa" + }, + "resources": [ + { + "resource": "service:plex", + "entries": [ + { + "name": "PLEX_LOG_LEVEL", + "running": "info", + "other": "debug" + }, + { + "name": "PLEX_TOKEN", + "masked": true + } + ] + } + ] + } + }, + { + "name": "composition-diff answers no resource when none differs", + "of": "verb:composition-diff.answer", + "given": { + "node": "ace", + "module": "plex", + "running": "sha256:aa", + "resources": [] + } } ] diff --git a/seats/node-engine/seat.json b/seats/node-engine/seat.json index 46220d9..cb12b6f 100644 --- a/seats/node-engine/seat.json +++ b/seats/node-engine/seat.json @@ -550,6 +550,63 @@ }, "class": "read" }, + { + "name": "composition-diff", + "description": "One module's composed values read by resource (design 47 H2 \u00a7813 (3), H-A-349 DQ-12b): given a module and a revision or a digest of its composition, the entries that differ between the composition that runs and that one, per resource, environment entries by name, a secret's value masked. Read-only. Answered by this machine's engine alone.", + "class": "read", + "input": { + "type": "object", + "required": [ + "module" + ], + "properties": { + "module": { + "type": "string", + "description": "the module, as placed on this machine; node for the node's own" + }, + "revision": { + "type": "integer", + "description": "the revision of the module's composition key to compare with, from the revisions the bucket keeps; give it or digest" + }, + "digest": { + "type": "string", + "description": "the digest (sha256:\u2026) of the composition to compare with; give it or revision" + } + } + }, + "answer": { + "type": "object", + "required": [ + "node", + "module", + "resources" + ], + "properties": { + "node": { + "type": "string", + "description": "the node" + }, + "module": { + "type": "string", + "description": "the module" + }, + "running": { + "type": "string", + "description": "the digest of the composition that runs; absent when nothing runs" + }, + "other": { + "$ref": "#/defs/Revision" + }, + "resources": { + "type": "array", + "description": "each resource with an entry that differs; empty when none differs", + "items": { + "$ref": "#/defs/CompositionDiffResource" + } + } + } + } + }, { "name": "compose", "description": "Compose this machine's modules now and say how it went, so a composition that failed, or a module held, recovers without a restart: what the pass refused or held, each with why, and when the engine composes again on its own after a seat that did not answer (a deadline, no responders: retried with a growing wait; a refusal never). With module, that module's apply is also tried again. Changes only what a pass the engine makes on its own would change.", @@ -3398,6 +3455,52 @@ "step", "since" ] + }, + "CompositionDiffEntry": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "description": "the entry: an environment entry by its name, else the part of the resource that differs" + }, + "running": { + "type": "string", + "description": "its value in the running composition; absent where the running one lacks it or the value is a secret" + }, + "other": { + "type": "string", + "description": "its value in the other composition; absent where the other lacks it or the value is a secret" + }, + "masked": { + "type": "boolean", + "description": "the value is a secret, so neither value is given" + } + }, + "description": "one entry that differs between the running composition and the other" + }, + "CompositionDiffResource": { + "type": "object", + "required": [ + "resource", + "entries" + ], + "properties": { + "resource": { + "type": "string", + "description": "the resource, as the composition names it" + }, + "entries": { + "type": "array", + "items": { + "$ref": "#/defs/CompositionDiffEntry" + }, + "description": "the entries of the resource that differ" + } + }, + "description": "one resource with the entries of it that differ" } } } diff --git a/ts/seats/nodeengine/index.d.ts b/ts/seats/nodeengine/index.d.ts index eb6830a..6858c26 100644 --- a/ts/seats/nodeengine/index.d.ts +++ b/ts/seats/nodeengine/index.d.ts @@ -13,6 +13,7 @@ export declare const verbs: { readonly acts: "acts"; readonly packages: "packages"; readonly composition: "composition"; + readonly compositionDiff: "composition-diff"; readonly compose: "compose"; readonly composeCandidate: "compose-candidate"; readonly manifestReads: "manifest-reads"; @@ -304,6 +305,26 @@ export interface Composed { "v": number; } +/** one entry that differs between the running composition and the other */ +export interface CompositionDiffEntry { + /** the value is a secret, so neither value is given */ + "masked"?: boolean; + /** the entry: an environment entry by its name, else the part of the resource that differs */ + "name": string; + /** its value in the other composition; absent where the other lacks it or the value is a secret */ + "other"?: string; + /** its value in the running composition; absent where the running one lacks it or the value is a secret */ + "running"?: string; +} + +/** one resource with the entries of it that differ */ +export interface CompositionDiffResource { + /** the entries of the resource that differ */ + "entries": CompositionDiffEntry[]; + /** the resource, as the composition names it */ + "resource": string; +} + /** a group */ export interface DeclaredGroup { "gid": number; @@ -963,6 +984,29 @@ export interface CompositionAnswer { "withheld-unknown"?: string; } +/** is what composition-diff takes. */ +export interface CompositionDiffInput { + /** the digest (sha256:…) of the composition to compare with; give it or revision */ + "digest"?: string; + /** the module, as placed on this machine; node for the node's own */ + "module": string; + /** the revision of the module's composition key to compare with, from the revisions the bucket keeps; give it or digest */ + "revision"?: number; +} + +/** is what composition-diff answers. */ +export interface CompositionDiffAnswer { + /** the module */ + "module": string; + /** the node */ + "node": string; + "other"?: Revision; + /** each resource with an entry that differs; empty when none differs */ + "resources": CompositionDiffResource[]; + /** the digest of the composition that runs; absent when nothing runs */ + "running"?: string; +} + /** is what compose takes. */ export interface ComposeInput { /** a module placed on this machine whose apply is also tried again (optional) */ diff --git a/ts/seats/nodeengine/index.js b/ts/seats/nodeengine/index.js index 56850c7..245c586 100644 --- a/ts/seats/nodeengine/index.js +++ b/ts/seats/nodeengine/index.js @@ -13,6 +13,7 @@ export const verbs = { acts: "acts", packages: "packages", composition: "composition", + compositionDiff: "composition-diff", compose: "compose", composeCandidate: "compose-candidate", manifestReads: "manifest-reads",