// Command mailstore refuses any manifest but modules/mesh-mail claiming the mail-store seat (novox/hq ADR 0378 // §3, issue 800 part A): the operator's mail is read, searched and sent through this one seat, and a second // claimant would be a second path to the same mail that ADR 0378 never accounted for. // // go run . // // Exits 1 on a finding. package main import ( "encoding/json" "fmt" "os" "path/filepath" "sort" ) // MailStoreSeat is the seat only mesh-mail may claim. const MailStoreSeat = "mail-store" // MailStoreModule is the one module allowed to claim it. const MailStoreModule = "mesh-mail" // Finding is one manifest refused: a module other than mesh-mail claiming mail-store. type Finding struct { Module string } // Check reads every manifest under root/modules and answers which ones it refuses. func Check(root string) ([]Finding, error) { manifests, err := filepath.Glob(filepath.Join(root, "modules", "*", "module.json")) if err != nil { return nil, err } sort.Strings(manifests) var out []Finding for _, path := range manifests { raw, err := os.ReadFile(path) if err != nil { return nil, err } var m struct { Module string `json:"module"` Claims []struct { Name string `json:"name"` } `json:"claims"` } if err := json.Unmarshal(raw, &m); err != nil { return nil, fmt.Errorf("%s: %w", path, err) } if m.Module == MailStoreModule { continue } for _, c := range m.Claims { if c.Name == MailStoreSeat { out = append(out, Finding{Module: m.Module}) break } } } return out, nil } func main() { root := "." if len(os.Args) > 1 { root = os.Args[1] } found, err := Check(root) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } for _, f := range found { fmt.Printf("%s claims the mail-store seat: only %s may (novox/hq ADR 0378 §3)\n", f.Module, MailStoreModule) } if len(found) > 0 { os.Exit(1) } fmt.Println("mail-store: claimed only by mesh-mail") }