gunk-dev/the-valley

main.go

source823c1f15e175main's published tip history
25.2 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
190 // The programs it drives. Every judgement about a statement or a note
191 // is attest's, and every judgement about what a policy says is the
192 // deriver's and cue's.
193 attest string
194 valley string
195 cue string
196 nats string
197
198 attestSchema string
199 eventSchema string
200 policy policySource
201
202 key string
203 signerName string
204 keyHash string
205 knownSigners string
206
207 // signerProjects restricts signers in knownSigners to projects
208 // (note/signerprojects.go). Nil restricts nobody. It is read once, at
209 // start, and signerProjectsData is the bytes it was read from, which
210 // the inputs digest covers (inputs.go).
211 signerProjects note.SignerProjects
212 signerProjectsData []byte
213
214 bus string
215 publishQueue string
216 wake string // the check worker's wake directory, or empty
217 system string
218
219 // floorReaders are the wake directories of the controllers that read
220 // the floor this controller lands, marked after a landing on the
221 // floor's ref (bus.go). Empty for every controller but the instance
222 // repository's.
223 floorReaders []string
224
225 // landings counts the landings this process has made, so watch can
226 // tell a pass that landed something and follow it with another.
227 landings int
228
229 // clock, when set, is the instant the effectful window is measured
230 // against. Zero means the wall clock.
231 clock time.Time
232
233 // evidenceListed, when set, runs once collectEvidence has listed a
234 // subject's attestation refs, before it reads any of them. Tests set
235 // it to delete a ref in that window.
236 evidenceListed func()
237}
238
239func main() {
240 if len(os.Args) < 2 {
241 fmt.Fprint(os.Stderr, usage)
242 os.Exit(2)
243 }
244 // Before anything runs git, so that every git this process starts — its
245 // own, and the ones attest and the deriver start — inherits the result.
246 os.Clearenv()
247 for _, kv := range gitEnvironment(environ) {
248 name, value, _ := strings.Cut(kv, "=")
249 os.Setenv(name, value)
250 }
251 var err error
252 switch os.Args[1] {
253 case "reconcile":
254 err = run(os.Args[2:], false)
255 case "watch":
256 err = run(os.Args[2:], true)
257 case "publish-signers":
258 err = publishSigners(os.Args[2:])
259 case "help", "-h", "--help":
260 fmt.Print(usage)
261 return
262 default:
263 fmt.Fprintf(os.Stderr, "integrator: unknown command %q\n\n%s", os.Args[1], usage)
264 os.Exit(2)
265 }
266 if err != nil {
267 fmt.Fprintf(os.Stderr, "integrator: %v\n", err)
268 os.Exit(1)
269 }
270}
271
272func run(args []string, loop bool) error {
273 fs := flag.NewFlagSet("integrator", flag.ExitOnError)
274 fs.Usage = func() { fmt.Fprint(os.Stderr, usage) }
275 repo := fs.String("repo", ".", "the served repository")
276 project := fs.String("project", "", "the project name events carry")
277 key := fs.String("key", "", "ed25519 private key")
278 name := fs.String("name", defaultSignerName(), "the name that key signs under")
279 known := fs.String("known-signers", "", "verifier keys whose attestations count")
280 signerProjects := fs.String("signer-projects", "", "signers whose attestations count only in the projects listed beside them")
281 instanceRepo := fs.String("instance-repo", "", "the bare repository carrying the group's floor")
282 instanceRef := fs.String("instance-ref", "refs/heads/main", "the ref whose tip carries the floor")
283 instancePolicy := fs.String("instance-policy", "policy/instance", "the floor's directory in that tip")
284 instance := fs.String("instance", "", "a materialized instance policy layer")
285 projectPolicy := fs.String("project-policy", "policy/project", "the project policy layer, relative to the target tip")
286 schema := fs.String("schema", env("VALLEY_VERIFICATION_SCHEMA"), "the verification schema")
287 attestSchema := fs.String("attest-schema", env("VALLEY_ATTEST_SCHEMA"), "the attestation schema")
288 eventSchema := fs.String("event-schema", env("VALLEY_EVENT_SCHEMA"), "the event vocabulary")
289 bus := fs.String("bus", "", "nats server to publish outcomes to")
290 publishQueue := fs.String("publish-queue", "", "the host's queue of ref moves to publish")
291 wake := fs.String("wake", "", "the check worker's wake directory, marked due after each landing")
292 var floorReaders dirList
293 fs.Var(&floorReaders, "wake-floor-reader", "a floor-reading controller's wake directory, marked due after each floor landing")
294 wokenBy := fs.String("woken-by", "", "watch: this controller's own wake directory")
295 system := fs.String("system", "", "flake system")
296 interval := fs.Duration("interval", 15*time.Second, "how long to wait between passes")
297 now := fs.String("now", "", "judge as at this instant")
298 if err := fs.Parse(args); err != nil {
299 return err
300 }
301
302 in := &integrator{
303 repo: *repo,
304 project: *project,
305 out: os.Stdout,
306 timings: newDroppable(duplicate(syscall.Stdout, "stdout")),
307 attestSchema: *attestSchema,
308 eventSchema: *eventSchema,
309 key: *key,
310 signerName: *name,
311 knownSigners: *known,
312 bus: *bus,
313 publishQueue: *publishQueue,
314 wake: *wake,
315 system: *system,
316 floorReaders: floorReaders,
317 }
318 for _, missing := range []struct{ flag, value string }{
319 {"--key", in.key},
320 {"--known-signers", in.knownSigners},
321 {"--schema", *schema},
322 {"--attest-schema", in.attestSchema},
323 } {
324 if missing.value == "" {
325 return fmt.Errorf("%s is required", missing.flag)
326 }
327 }
328 var err error
329 for _, tool := range []struct {
330 name string
331 into *string
332 }{{"attest", &in.attest}, {"valley", &in.valley}, {"cue", &in.cue}, {"nats", &in.nats}} {
333 if *tool.into, err = exec.LookPath(tool.name); err != nil && tool.name != "nats" {
334 return fmt.Errorf("%s is not on the path; the integrator drives it rather than reimplementing it", tool.name)
335 }
336 }
337 // The floor comes from the instance repository's integrated tip, or from
338 // a directory on disk, and never from both — two sources for one layer is
339 // a question about which one won every time the policy is read.
340 if (*instanceRepo == "") == (*instance == "") {
341 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")
342 }
343 // abs of an empty path is the working directory, and an empty field is
344 // how the layer says which of its two sources it is.
345 layer := composed.Floor{Ref: *instanceRef, Dir: *instancePolicy}
346 if *instanceRepo != "" {
347 // A full ref name is read by that exact name. Any other name,
348 // such as main, git would resolve by trying several refs in
349 // turn, and a pusher can make one of them.
350 if !strings.HasPrefix(*instanceRef, "refs/") {
351 return fmt.Errorf("--instance-ref %s is not a full ref name; name it whole, as refs/heads/main", *instanceRef)
352 }
353 layer.Repo = abs(*instanceRepo)
354 } else {
355 layer.Path = abs(*instance)
356 }
357 in.policy = policySource{
358 schema: abs(*schema),
359 layer: layer,
360 projectDir: *projectPolicy,
361 valley: in.valley,
362 cue: in.cue,
363 }
364 if *now != "" {
365 if in.clock, err = time.Parse(time.RFC3339, *now); err != nil {
366 return fmt.Errorf("--now: %w", err)
367 }
368 }
369 if in.repo, err = filepath.Abs(in.repo); err != nil {
370 return err
371 }
372 if in.project == "" {
373 in.project = projectName(in.repo)
374 }
375 if in.signerProjects, in.signerProjectsData, err = readSignerProjects(*signerProjects, in.signerName); err != nil {
376 return err
377 }
378 if in.keyHash, err = in.readKeyHash(); err != nil {
379 return err
380 }
381 if len(in.floorReaders) > 0 && !landsFloor(in.repo, layer) {
382 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")
383 }
384 // A wake directory is consumed by one long-lived controller. A
385 // reconcile run by hand beside it must not take its marks.
386 if *wokenBy != "" && !loop {
387 return fmt.Errorf("--woken-by is watch's: reconcile reads no wake directory")
388 }
389 if *wokenBy != "" && !wakeSupported {
390 return fmt.Errorf("--woken-by: watching a wake directory needs Linux's inotify; run watch without it to pass at --interval")
391 }
392 if loop && *interval <= 0 {
393 return fmt.Errorf("--interval %s: the recovery interval must be positive", *interval)
394 }
395
396 if !loop {
397 return in.reconcile()
398 }
399 // Only the looping controller sweeps. A one-shot run may be somebody
400 // running the integrator by hand beside a controller that is already
401 // watching this repository, and sweeping from there would pull the
402 // worktree out from under a tick in progress.
403 //
404 // One controller serves a repository (own_unix.go). Its lock comes
405 // before the sweep, so a second watch over the same repository stops
406 // before it can sweep a worktree out from under the first, and the lock
407 // is checked again before every pass.
408 return serve(in.repo, sweepScratch, func(owned func() error) error {
409 if *wokenBy == "" {
410 for {
411 if err := owned(); err != nil {
412 return err
413 }
414 if err := in.reconcile(); err != nil {
415 fmt.Fprintf(os.Stderr, "integrator: %v\n", err)
416 }
417 time.Sleep(*interval)
418 }
419 }
420 l := &wakeLoop{
421 dir: abs(*wokenBy),
422 interval: *interval,
423 stderr: os.Stderr,
424 watch: watchDir,
425 owned: owned,
426 pass: func(reason passReason) (bool, error) {
427 in.out = newPassOutput(os.Stdout, reason)
428 before := in.landings
429 err := in.reconcile()
430 return in.landings > before, err
431 },
432 }
433 return l.run()
434 })
435}
436
437// serve is a watch's start: it takes the repository's lock, then sweeps
438// the repository's scratch, then runs the loop, which asks owned before
439// every pass. A watch that cannot take the lock does neither, and holds
440// nothing when it returns.
441func serve(repo string, sweep func(string), loop func(owned func() error) error) error {
442 owner, err := ownRepo(repo)
443 if err != nil {
444 return err
445 }
446 defer owner.Close()
447 sweep(repo)
448 return loop(owner.check)
449}
450
451// dirList is a flag given once per directory.
452type dirList []string
453
454func (d *dirList) String() string { return strings.Join(*d, ",") }
455
456func (d *dirList) Set(dir string) error {
457 if dir == "" {
458 return fmt.Errorf("an empty directory marks nothing")
459 }
460 *d = append(*d, abs(dir))
461 return nil
462}
463
464// landsFloor says whether the repository this controller serves is the one
465// its floor is read from, so a landing there can move the floor.
466func landsFloor(repo string, layer composed.Floor) bool {
467 if layer.Repo == "" {
468 return false
469 }
470 a, err := os.Stat(repo)
471 if err != nil {
472 return false
473 }
474 b, err := os.Stat(layer.Repo)
475 return err == nil && os.SameFile(a, b)
476}
477
478// readKeyHash asks attest for the verifier key this integrator signs under,
479// and keeps the key hash: it is the segment that keeps one signer's
480// attestation ref from racing another's (dcr-0de694f).
481func (in *integrator) readKeyHash() (string, error) {
482 out, err := exec.Command(in.attest, "key", "--key", in.key, "--name", in.signerName).Output()
483 if err != nil {
484 return "", fmt.Errorf("reading the signing key: %w", err)
485 }
486 // name+hash+base64, split three ways: the name holds no plus and the
487 // base64 may.
488 fields := strings.SplitN(strings.TrimSpace(string(out)), "+", 3)
489 if len(fields) != 3 {
490 return "", fmt.Errorf("attest key printed %q", strings.TrimSpace(string(out)))
491 }
492 if _, err := strconv.ParseUint(fields[1], 16, 32); err != nil {
493 return "", fmt.Errorf("attest key printed the hash %q", fields[1])
494 }
495 return fields[1], nil
496}
497
498// projectName is the name the events carry: the repository's directory,
499// with a bare repo's .git suffix removed — the same name the post-receive
500// hook derives.
501func projectName(repo string) string {
502 if bare, err := gitLine(repo, "rev-parse", "--is-bare-repository"); err == nil && bare == "true" {
503 dir, _ := gitLine(repo, "rev-parse", "--absolute-git-dir")
504 return strings.TrimSuffix(filepath.Base(dir), ".git")
505 }
506 top, err := gitLine(repo, "rev-parse", "--show-toplevel")
507 if err != nil {
508 return filepath.Base(repo)
509 }
510 return filepath.Base(top)
511}
512
513// defaultSignerName is the name this machine signs under: its own name and
514// the suffix that keeps a key signing attestations distinct from the same
515// key signing anything else (dcr-de9d996).
516func defaultSignerName() string {
517 host, err := os.Hostname()
518 if err != nil || host == "" {
519 host = "localhost"
520 }
521 return host + "/attestations"
522}
523
524func env(name string) string { return os.Getenv(name) }
525
526// environ is the environment the process started with, read before main
527// replaces it.
528var environ = os.Environ()
529
530// gitEnvironment is the environment the controller runs in: the one it
531// started with, with git's part of it fixed.
532//
533// Replacement refs are off. A replacement ref makes one object stand in for
534// another wherever git looks it up, so a refs/replace/<blob> pushed to the
535// served repository or the instance repository could swap the floor, the
536// project's policy or a change's tree for anything its author liked,
537// without moving any ref the controller watches. Every judgement here reads
538// the repository's own objects.
539//
540// No other GIT_ variable is inherited, as sigverify inherits none: a GIT_DIR
541// or GIT_OBJECT_DIRECTORY could point git at other objects, and a
542// GIT_CONFIG_PARAMETERS could change how it reads them. System and user
543// configuration are not read either. The one thing kept is command-scope
544// configuration naming safe.directory, which is how the unit tells git it
545// may read repositories the controller does not own (nix/valley-host.nix).
546// Those entries are carried over, renumbered, and no other key is.
547func gitEnvironment(inherited []string) []string {
548 vars := map[string]string{}
549 var kept []string
550 for _, kv := range inherited {
551 name, value, _ := strings.Cut(kv, "=")
552 if strings.HasPrefix(name, "GIT_") {
553 vars[name] = value
554 continue
555 }
556 kept = append(kept, kv)
557 }
558
559 var safe []string
560 count, _ := strconv.Atoi(vars["GIT_CONFIG_COUNT"])
561 for i := 0; i < count; i++ {
562 if strings.EqualFold(vars[fmt.Sprintf("GIT_CONFIG_KEY_%d", i)], "safe.directory") {
563 safe = append(safe, vars[fmt.Sprintf("GIT_CONFIG_VALUE_%d", i)])
564 }
565 }
566 if len(safe) > 0 {
567 kept = append(kept, fmt.Sprintf("GIT_CONFIG_COUNT=%d", len(safe)))
568 for i, dir := range safe {
569 kept = append(kept,
570 fmt.Sprintf("GIT_CONFIG_KEY_%d=safe.directory", i),
571 fmt.Sprintf("GIT_CONFIG_VALUE_%d=%s", i, dir))
572 }
573 }
574
575 return append(kept,
576 "GIT_CONFIG_NOSYSTEM=1",
577 "GIT_CONFIG_SYSTEM=/dev/null",
578 "GIT_CONFIG_GLOBAL=/dev/null",
579 "GIT_NO_REPLACE_OBJECTS=1",
580 "GIT_ATTR_NOSYSTEM=1",
581 "GIT_TERMINAL_PROMPT=0",
582 )
583}
584
585func abs(path string) string {
586 if p, err := filepath.Abs(path); err == nil {
587 return p
588 }
589 return path
590}
591
592// gitEnv runs a git command with extra environment, for the one place the
593// integrator has to state who authored and who committed.
594func (in *integrator) gitEnv(extra map[string]string, args ...string) (string, error) {
595 cmd := exec.Command("git", args...)
596 cmd.Dir = in.repo
597 cmd.Env = os.Environ()
598 for k, v := range extra {
599 cmd.Env = append(cmd.Env, k+"="+v)
600 }
601 var errb strings.Builder
602 cmd.Stderr = &errb
603 out, err := cmd.Output()
604 if err != nil {
605 return "", fmt.Errorf("git %s: %w: %s", strings.Join(args, " "), err, strings.TrimSpace(errb.String()))
606 }
607 return string(out), nil
608}
609
610// writeTemp writes bytes to a file cue will read as JSON — the extension is
611// how cue tells a data file from a schema.
612func writeTemp(prefix string, body []byte) (string, error) {
613 dir, err := scratch(prefix)
614 if err != nil {
615 return "", err
616 }
617 path := filepath.Join(dir, "payload.json")
618 if err := os.WriteFile(path, body, 0o644); err != nil {
619 return "", err
620 }
621 return path, nil
622}
623
624func removeTemp(path string) { _ = os.RemoveAll(filepath.Dir(path)) }