gunk-dev/the-valley

main.go

source58e68be0d151main's published tip history
25.4 KiB
1// integrator is the Phase 3 controller that lands changes by verifying
2// evidence (archive/design/roadmap.md). It is a single writer per target stream and
3// the commit point of dcr-439b771: it applies a change's delta to the
4// current tip, checks per required check that the contributor's evidence
5// still transfers, and either fast-forwards the protected ref or says which
6// checks need new evidence.
7//
8// It runs no check. Verification happens where a change is authored, and
9// the serialized section here is digest comparison and a ref write.
10package main
11
12import (
13 "the-valley/composed"
14 "the-valley/note"
15
16 "flag"
17 "fmt"
18 "io"
19 "os"
20 "os/exec"
21 "path/filepath"
22 "strconv"
23 "strings"
24 "syscall"
25 "time"
26)
27
28const usage = `usage: integrator <command> [flags]
29
30 reconcile judge every pending integration request once, and act
31 watch reconcile at start, when woken and on an interval,
32 until interrupted
33 publish-signers publish what clients verify transfer statements with
34 (integrator publish-signers --help)
35 help print this message
36
37The integrator level-triggers over refs. Integration requests are durable
38in git — refs/the-valley/integration-requests/<target>/<change>, whose
39commit is the change's head — and the bus is a projection over them, so
40each pass reads the refs as they are and converges. It publishes its
41outcomes to the bus and consumes nothing from it. What starts a pass is
42the start, the interval, and, given --woken-by, a mark in its own wake
43directory (see below). A mark only starts a pass: it carries nothing, and
44what a pass decides comes from the refs it reads.
45
46The commit rule (dcr-439b771). The delta must apply cleanly to the tip; a
47conflict is new authorship, so every check is re-demanded. Then, per check
48the policy requires: a pure check transfers when its input-closure digest
49recomputed on the landed tree equals the attested one, and an effectful
50check transfers while no intervening landing has touched its requiring
51class's paths and its observation is inside the validity window the policy
52declares. Anything left standing lands; anything invalidated surfaces as
53one request-stale event naming exactly those checks, and the request stays
54for approving again.
55
56Before the commit rule, the change records can refuse a request. A request
57named c-<change ID> is that change's, and lands only while the record at
58refs/the-valley/changes/<target>/<change ID> says ready and lists the
59request's head as one of its versions'. A request of any name does not land
60while any commit it brings is a version of a change whose record is not
61ready. Both refuse with refused-not-ready. A request whose commits from the
62merge base to the head include a merge is refused-merge. A refused request
63stays where it is, and is decided again on every pass, so a change readied
64again is judged on the next one. Every record is read again just before
65the target moves, and a record never makes a request land.
66
67A withdrawn change voids its requests: each pass deletes the requests named
68for it or at one of its version heads, as voided-withdrawn, so readying it
69again needs a fresh approval. A record that does not read refuses nothing,
70and is reported with a WARNING on every pass that reads records.
71
72flags:
73 --repo DIR the served repository (default: here)
74 --project NAME the project name events carry (default: the repo's)
75 --key PATH ed25519 private key the integrator signs with
76 --name NAME the name that key signs under (default: this host's)
77 --known-signers F verifier keys whose attestations count, one per line
78 --signer-projects F signers whose attestations count only in the projects
79 listed beside them (see below); read once, at start, so a
80 changed file counts from the next start
81 --instance-repo DIR the bare repository carrying the group's floor; the
82 instance layer is read from its integrated tip
83 --instance-ref REF the ref whose tip carries it, a full ref name read by
84 that exact name (default refs/heads/main)
85 --instance-policy P the floor's directory in that tip (default
86 policy/instance); a floor that is not there is refused
87 --instance DIR a materialized instance layer, for a host that serves
88 no instance repository; one of this or --instance-repo
89 --project-policy P the project policy layer, relative to the target tip
90 (default policy/project); a target that carries none
91 is judged under the floor alone
92 --schema FILE the verification schema
93 --attest-schema F the attestation schema
94 --event-schema F the event vocabulary payloads are vetted against
95 --bus URL nats server to publish outcomes to; empty publishes
96 nothing and still prints every payload
97 --publish-queue DIR the host's queue of ref moves to publish: each landing
98 leaves its target's move there, and the host pushes it
99 to the mirrors as it does a pushed one; empty leaves
100 nothing
101 --wake DIR the host check worker's wake directory: each landing
102 creates the empty file DIR/due, before the mirror
103 queue and the bus, so the worker starts a pass;
104 empty marks nothing. Output only; --woken-by is what
105 wakes this controller
106 --wake-floor-reader DIR
107 another controller's wake directory, which reads the
108 floor this one lands: each landing on --instance-ref
109 creates the empty file DIR/due, after the worker's
110 mark and before the mirror queue and the bus. Only the
111 controller serving --instance-repo takes it. Repeat it
112 for each reader
113 --woken-by DIR watch: this controller's own wake directory (Linux
114 only). A pass starts soon after a writer creates
115 DIR/due, and once more after any pass that lands
116 something; see below
117 --system SYSTEM flake system for closure recomputation
118 --interval D watch: how long to wait after a pass before the next,
119 when nothing starts one sooner (default 15s)
120 --now TIME judge as at this RFC 3339 instant, for the effectful
121 window; defaults to the clock
122
123Every program the controller runs reads git with replacement refs off. A
124replacement ref makes one object stand in for another wherever git looks
125it up, so a pushed refs/replace/* could swap the floor, a project's policy
126or a change's tree without moving any ref the controller watches. No GIT_
127variable is inherited except the safe.directory entries of command-scope
128configuration, and system and user configuration are not read.
129
130--woken-by is how a controller starts a pass promptly. A writer that moves
131a ref the controller reads creates the empty file DIR/due with
132O_CREAT|O_EXCL, and a due already there is a mark already made. The
133controller watches DIR with inotify, removes due before a pass reads any
134ref, and starts the next pass when the pass ends if due is there again,
135so a mark made during a pass is never lost. While it watches DIR it holds
136a lock on DIR itself, so a second controller given the same DIR consumes
137no mark from it and passes at its interval. reconcile never reads DIR. The
138interval stays the recovery pass: a missed mark, a
139watch that failed and a missing directory are all covered by the next
140timer pass. A due that cannot be removed starts no pass until the next
141timer pass, and a pass that failed is followed by another no sooner than
14210s later. Each pass opens with the line "pass: REASON", where REASON is
143startup, due, timer, follow-up or watcher; a timer pass with nothing else
144to say prints nothing.
145
146One watch serves a repository at a time. watch takes an exclusive lock on
147the --repo directory before it sweeps its scratch or judges anything, and
148checks before every pass that the path still names the directory it
149locked. A second watch over the same repository stops at its start, and a
150watch whose repository path comes to name another directory stops. A
151reconcile run by hand takes no lock.
152
153--known-signers is the registry's interim compilation. Identity is a
154governed registry (dcr-b87f6e8) whose entries compile into what each
155enforcement boundary checks; no compiler exists yet, so the file is
156supplied directly and is exactly what dcr-b87f6e8 calls the first
157compilation's output. An attestation signed by nobody in it does not
158transfer, and that is reported per check rather than treated as a forgery.
159
160--signer-projects restricts signers to projects. Each line names a signer,
161then the projects its attestations count in, separated by spaces:
162
163 worker/attestations the-valley app
164
165A signer the file names counts only in the projects on its line, where the
166project is the name events carry. In any other project its attestations
167are reported as signed by no signer the integrator holds. A line with a
168name and no project lets that signer count nowhere. A signer the file does
169not name counts wherever the known-signers file lets it. Blank lines and
170lines that open with # are skipped. Every name and project is a word of
171printable ASCII. A file that cannot be read, names a signer twice, holds
172a word that is not printable ASCII, names a signer no verifier key can
173carry, or names the integrator's own --name stops the integrator before
174it judges anything.
175
176The integrator's own signature never makes a check's attestation count.
177It countersigns the attestations a landing carried, and that vouches for
178the landing; a countersigned attestation counts, in any project, only
179through another signer who counts there.
180`
181
182// integrator is one controller: which repository it serves, who it signs
183// as, whose evidence it accepts, and where it finds the policy.
184type integrator struct {
185 repo string
186 project string
187 out io.Writer
188 timings io.Writer // where timing lines go (timing.go); nil prints none
189 // sightings is when this process first saw each request, which timing
190 // lines report and nothing else reads (timing.go). Nil sees none.
191 sightings *sightings
192
193 // The programs it drives. Every judgement about a statement or a note
194 // is attest's, and cue composes the policy the integrator derives
195 // required checks from.
196 attest string
197 cue string
198 nats string
199
200 attestSchema string
201 eventSchema string
202 policy policySource
203
204 key string
205 signerName string
206 keyHash string
207 knownSigners string
208
209 // signerProjects restricts signers in knownSigners to projects
210 // (note/signerprojects.go). Nil restricts nobody. It is read once, at
211 // start, and signerProjectsData is the bytes it was read from, which
212 // the inputs digest covers (inputs.go).
213 signerProjects note.SignerProjects
214 signerProjectsData []byte
215
216 bus string
217 publishQueue string
218 wake string // the check worker's wake directory, or empty
219 system string
220
221 // floorReaders are the wake directories of the controllers that read
222 // the floor this controller lands, marked after a landing on the
223 // floor's ref (bus.go). Empty for every controller but the instance
224 // repository's.
225 floorReaders []string
226
227 // landings counts the landings this process has made, so watch can
228 // tell a pass that landed something and follow it with another.
229 landings int
230
231 // clock, when set, is the instant the effectful window is measured
232 // against. Zero means the wall clock.
233 clock time.Time
234
235 // evidenceListed, when set, runs once collectEvidence has listed a
236 // subject's attestation refs, before it reads any of them. Tests set
237 // it to delete a ref in that window.
238 evidenceListed func()
239}
240
241func main() {
242 if len(os.Args) < 2 {
243 fmt.Fprint(os.Stderr, usage)
244 os.Exit(2)
245 }
246 // Before anything runs git, so that every git this process starts — its
247 // own and the ones attest starts — inherits the result.
248 os.Clearenv()
249 for _, kv := range gitEnvironment(environ) {
250 name, value, _ := strings.Cut(kv, "=")
251 os.Setenv(name, value)
252 }
253 var err error
254 switch os.Args[1] {
255 case "reconcile":
256 err = run(os.Args[2:], false)
257 case "watch":
258 err = run(os.Args[2:], true)
259 case "publish-signers":
260 err = publishSigners(os.Args[2:])
261 case "help", "-h", "--help":
262 fmt.Print(usage)
263 return
264 default:
265 fmt.Fprintf(os.Stderr, "integrator: unknown command %q\n\n%s", os.Args[1], usage)
266 os.Exit(2)
267 }
268 if err != nil {
269 fmt.Fprintf(os.Stderr, "integrator: %v\n", err)
270 os.Exit(1)
271 }
272}
273
274func run(args []string, loop bool) error {
275 fs := flag.NewFlagSet("integrator", flag.ExitOnError)
276 fs.Usage = func() { fmt.Fprint(os.Stderr, usage) }
277 repo := fs.String("repo", ".", "the served repository")
278 project := fs.String("project", "", "the project name events carry")
279 key := fs.String("key", "", "ed25519 private key")
280 name := fs.String("name", defaultSignerName(), "the name that key signs under")
281 known := fs.String("known-signers", "", "verifier keys whose attestations count")
282 signerProjects := fs.String("signer-projects", "", "signers whose attestations count only in the projects listed beside them")
283 instanceRepo := fs.String("instance-repo", "", "the bare repository carrying the group's floor")
284 instanceRef := fs.String("instance-ref", "refs/heads/main", "the ref whose tip carries the floor")
285 instancePolicy := fs.String("instance-policy", "policy/instance", "the floor's directory in that tip")
286 instance := fs.String("instance", "", "a materialized instance policy layer")
287 projectPolicy := fs.String("project-policy", "policy/project", "the project policy layer, relative to the target tip")
288 schema := fs.String("schema", env("VALLEY_VERIFICATION_SCHEMA"), "the verification schema")
289 attestSchema := fs.String("attest-schema", env("VALLEY_ATTEST_SCHEMA"), "the attestation schema")
290 eventSchema := fs.String("event-schema", env("VALLEY_EVENT_SCHEMA"), "the event vocabulary")
291 bus := fs.String("bus", "", "nats server to publish outcomes to")
292 publishQueue := fs.String("publish-queue", "", "the host's queue of ref moves to publish")
293 wake := fs.String("wake", "", "the check worker's wake directory, marked due after each landing")
294 var floorReaders dirList
295 fs.Var(&floorReaders, "wake-floor-reader", "a floor-reading controller's wake directory, marked due after each floor landing")
296 wokenBy := fs.String("woken-by", "", "watch: this controller's own wake directory")
297 system := fs.String("system", "", "flake system")
298 interval := fs.Duration("interval", 15*time.Second, "how long to wait between passes")
299 now := fs.String("now", "", "judge as at this instant")
300 if err := fs.Parse(args); err != nil {
301 return err
302 }
303
304 in := &integrator{
305 repo: *repo,
306 project: *project,
307 out: os.Stdout,
308 timings: newDroppable(duplicate(syscall.Stdout, "stdout")),
309 sightings: newSightings(),
310 attestSchema: *attestSchema,
311 eventSchema: *eventSchema,
312 key: *key,
313 signerName: *name,
314 knownSigners: *known,
315 bus: *bus,
316 publishQueue: *publishQueue,
317 wake: *wake,
318 system: *system,
319 floorReaders: floorReaders,
320 }
321 for _, missing := range []struct{ flag, value string }{
322 {"--key", in.key},
323 {"--known-signers", in.knownSigners},
324 {"--schema", *schema},
325 {"--attest-schema", in.attestSchema},
326 } {
327 if missing.value == "" {
328 return fmt.Errorf("%s is required", missing.flag)
329 }
330 }
331 var err error
332 for _, tool := range []struct {
333 name string
334 into *string
335 }{{"attest", &in.attest}, {"cue", &in.cue}, {"nats", &in.nats}} {
336 if *tool.into, err = exec.LookPath(tool.name); err != nil && tool.name != "nats" {
337 return fmt.Errorf("%s is not on the path; the integrator drives it rather than reimplementing it", tool.name)
338 }
339 }
340 // The floor comes from the instance repository's integrated tip, or from
341 // a directory on disk, and never from both — two sources for one layer is
342 // a question about which one won every time the policy is read.
343 if (*instanceRepo == "") == (*instance == "") {
344 return fmt.Errorf("exactly one of --instance-repo and --instance is required: the floor is read from the instance repository's tip, or from a materialized directory for a host that serves none")
345 }
346 // abs of an empty path is the working directory, and an empty field is
347 // how the layer says which of its two sources it is.
348 layer := composed.Floor{Ref: *instanceRef, Dir: *instancePolicy}
349 if *instanceRepo != "" {
350 // A full ref name is read by that exact name. Any other name,
351 // such as main, git would resolve by trying several refs in
352 // turn, and a pusher can make one of them.
353 if !strings.HasPrefix(*instanceRef, "refs/") {
354 return fmt.Errorf("--instance-ref %s is not a full ref name; name it whole, as refs/heads/main", *instanceRef)
355 }
356 layer.Repo = abs(*instanceRepo)
357 } else {
358 layer.Path = abs(*instance)
359 }
360 in.policy = policySource{
361 schema: abs(*schema),
362 layer: layer,
363 projectDir: *projectPolicy,
364 cue: in.cue,
365 }
366 if *now != "" {
367 if in.clock, err = time.Parse(time.RFC3339, *now); err != nil {
368 return fmt.Errorf("--now: %w", err)
369 }
370 }
371 if in.repo, err = filepath.Abs(in.repo); err != nil {
372 return err
373 }
374 if in.project == "" {
375 in.project = projectName(in.repo)
376 }
377 if in.signerProjects, in.signerProjectsData, err = readSignerProjects(*signerProjects, in.signerName); err != nil {
378 return err
379 }
380 if in.keyHash, err = in.readKeyHash(); err != nil {
381 return err
382 }
383 if len(in.floorReaders) > 0 && !landsFloor(in.repo, layer) {
384 return fmt.Errorf("--wake-floor-reader is for the controller that lands the floor: give it only with --instance-repo naming the repository --repo serves")
385 }
386 // A wake directory is consumed by one long-lived controller. A
387 // reconcile run by hand beside it must not take its marks.
388 if *wokenBy != "" && !loop {
389 return fmt.Errorf("--woken-by is watch's: reconcile reads no wake directory")
390 }
391 if *wokenBy != "" && !wakeSupported {
392 return fmt.Errorf("--woken-by: watching a wake directory needs Linux's inotify; run watch without it to pass at --interval")
393 }
394 if loop && *interval <= 0 {
395 return fmt.Errorf("--interval %s: the recovery interval must be positive", *interval)
396 }
397
398 if !loop {
399 return in.reconcile(reasonOnce)
400 }
401 // Only the looping controller sweeps. A one-shot run may be somebody
402 // running the integrator by hand beside a controller that is already
403 // watching this repository, and sweeping from there would pull the
404 // worktree out from under a tick in progress.
405 //
406 // One controller serves a repository (own_unix.go). Its lock comes
407 // before the sweep, so a second watch over the same repository stops
408 // before it can sweep a worktree out from under the first, and the lock
409 // is checked again before every pass.
410 return serve(in.repo, sweepScratch, func(owned func() error) error {
411 if *wokenBy == "" {
412 for reason := reasonStartup; ; reason = reasonTimer {
413 if err := owned(); err != nil {
414 return err
415 }
416 if err := in.reconcile(reason); err != nil {
417 fmt.Fprintf(os.Stderr, "integrator: %v\n", err)
418 }
419 time.Sleep(*interval)
420 }
421 }
422 l := &wakeLoop{
423 dir: abs(*wokenBy),
424 interval: *interval,
425 stderr: os.Stderr,
426 watch: watchDir,
427 owned: owned,
428 pass: func(reason passReason) (bool, error) {
429 in.out = newPassOutput(os.Stdout, reason)
430 before := in.landings
431 err := in.reconcile(reason)
432 return in.landings > before, err
433 },
434 }
435 return l.run()
436 })
437}
438
439// serve is a watch's start: it takes the repository's lock, then sweeps
440// the repository's scratch, then runs the loop, which asks owned before
441// every pass. A watch that cannot take the lock does neither, and holds
442// nothing when it returns.
443func serve(repo string, sweep func(string), loop func(owned func() error) error) error {
444 owner, err := ownRepo(repo)
445 if err != nil {
446 return err
447 }
448 defer owner.Close()
449 sweep(repo)
450 return loop(owner.check)
451}
452
453// dirList is a flag given once per directory.
454type dirList []string
455
456func (d *dirList) String() string { return strings.Join(*d, ",") }
457
458func (d *dirList) Set(dir string) error {
459 if dir == "" {
460 return fmt.Errorf("an empty directory marks nothing")
461 }
462 *d = append(*d, abs(dir))
463 return nil
464}
465
466// landsFloor says whether the repository this controller serves is the one
467// its floor is read from, so a landing there can move the floor.
468func landsFloor(repo string, layer composed.Floor) bool {
469 if layer.Repo == "" {
470 return false
471 }
472 a, err := os.Stat(repo)
473 if err != nil {
474 return false
475 }
476 b, err := os.Stat(layer.Repo)
477 return err == nil && os.SameFile(a, b)
478}
479
480// readKeyHash asks attest for the verifier key this integrator signs under,
481// and keeps the key hash: it is the segment that keeps one signer's
482// attestation ref from racing another's (dcr-0de694f).
483func (in *integrator) readKeyHash() (string, error) {
484 out, err := exec.Command(in.attest, "key", "--key", in.key, "--name", in.signerName).Output()
485 if err != nil {
486 return "", fmt.Errorf("reading the signing key: %w", err)
487 }
488 // name+hash+base64, split three ways: the name holds no plus and the
489 // base64 may.
490 fields := strings.SplitN(strings.TrimSpace(string(out)), "+", 3)
491 if len(fields) != 3 {
492 return "", fmt.Errorf("attest key printed %q", strings.TrimSpace(string(out)))
493 }
494 if _, err := strconv.ParseUint(fields[1], 16, 32); err != nil {
495 return "", fmt.Errorf("attest key printed the hash %q", fields[1])
496 }
497 return fields[1], nil
498}
499
500// projectName is the name the events carry: the repository's directory,
501// with a bare repo's .git suffix removed — the same name the post-receive
502// hook derives.
503func projectName(repo string) string {
504 if bare, err := gitLine(repo, "rev-parse", "--is-bare-repository"); err == nil && bare == "true" {
505 dir, _ := gitLine(repo, "rev-parse", "--absolute-git-dir")
506 return strings.TrimSuffix(filepath.Base(dir), ".git")
507 }
508 top, err := gitLine(repo, "rev-parse", "--show-toplevel")
509 if err != nil {
510 return filepath.Base(repo)
511 }
512 return filepath.Base(top)
513}
514
515// defaultSignerName is the name this machine signs under: its own name and
516// the suffix that keeps a key signing attestations distinct from the same
517// key signing anything else (dcr-de9d996).
518func defaultSignerName() string {
519 host, err := os.Hostname()
520 if err != nil || host == "" {
521 host = "localhost"
522 }
523 return host + "/attestations"
524}
525
526func env(name string) string { return os.Getenv(name) }
527
528// environ is the environment the process started with, read before main
529// replaces it.
530var environ = os.Environ()
531
532// gitEnvironment is the environment the controller runs in: the one it
533// started with, with git's part of it fixed.
534//
535// Replacement refs are off. A replacement ref makes one object stand in for
536// another wherever git looks it up, so a refs/replace/<blob> pushed to the
537// served repository or the instance repository could swap the floor, the
538// project's policy or a change's tree for anything its author liked,
539// without moving any ref the controller watches. Every judgement here reads
540// the repository's own objects.
541//
542// No other GIT_ variable is inherited, as sigverify inherits none: a GIT_DIR
543// or GIT_OBJECT_DIRECTORY could point git at other objects, and a
544// GIT_CONFIG_PARAMETERS could change how it reads them. System and user
545// configuration are not read either. The one thing kept is command-scope
546// configuration naming safe.directory, which is how the unit tells git it
547// may read repositories the controller does not own (nix/valley-host.nix).
548// Those entries are carried over, renumbered, and no other key is.
549func gitEnvironment(inherited []string) []string {
550 vars := map[string]string{}
551 var kept []string
552 for _, kv := range inherited {
553 name, value, _ := strings.Cut(kv, "=")
554 if strings.HasPrefix(name, "GIT_") {
555 vars[name] = value
556 continue
557 }
558 kept = append(kept, kv)
559 }
560
561 var safe []string
562 count, _ := strconv.Atoi(vars["GIT_CONFIG_COUNT"])
563 for i := 0; i < count; i++ {
564 if strings.EqualFold(vars[fmt.Sprintf("GIT_CONFIG_KEY_%d", i)], "safe.directory") {
565 safe = append(safe, vars[fmt.Sprintf("GIT_CONFIG_VALUE_%d", i)])
566 }
567 }
568 if len(safe) > 0 {
569 kept = append(kept, fmt.Sprintf("GIT_CONFIG_COUNT=%d", len(safe)))
570 for i, dir := range safe {
571 kept = append(kept,
572 fmt.Sprintf("GIT_CONFIG_KEY_%d=safe.directory", i),
573 fmt.Sprintf("GIT_CONFIG_VALUE_%d=%s", i, dir))
574 }
575 }
576
577 return append(kept,
578 "GIT_CONFIG_NOSYSTEM=1",
579 "GIT_CONFIG_SYSTEM=/dev/null",
580 "GIT_CONFIG_GLOBAL=/dev/null",
581 "GIT_NO_REPLACE_OBJECTS=1",
582 "GIT_ATTR_NOSYSTEM=1",
583 "GIT_TERMINAL_PROMPT=0",
584 )
585}
586
587func abs(path string) string {
588 if p, err := filepath.Abs(path); err == nil {
589 return p
590 }
591 return path
592}
593
594// gitEnv runs a git command with extra environment, for the one place the
595// integrator has to state who authored and who committed.
596func (in *integrator) gitEnv(extra map[string]string, args ...string) (string, error) {
597 cmd := exec.Command("git", args...)
598 cmd.Dir = in.repo
599 cmd.Env = os.Environ()
600 for k, v := range extra {
601 cmd.Env = append(cmd.Env, k+"="+v)
602 }
603 var errb strings.Builder
604 cmd.Stderr = &errb
605 out, err := cmd.Output()
606 if err != nil {
607 return "", fmt.Errorf("git %s: %w: %s", strings.Join(args, " "), err, strings.TrimSpace(errb.String()))
608 }
609 return string(out), nil
610}
611
612// writeTemp writes bytes to a file cue will read as JSON — the extension is
613// how cue tells a data file from a schema.
614func writeTemp(prefix string, body []byte) (string, error) {
615 dir, err := scratch(prefix)
616 if err != nil {
617 return "", err
618 }
619 path := filepath.Join(dir, "payload.json")
620 if err := os.WriteFile(path, body, 0o644); err != nil {
621 return "", err
622 }
623 return path, nil
624}
625
626func removeTemp(path string) { _ = os.RemoveAll(filepath.Dir(path)) }