main.go, still the copy both holders of node-uplink carry, now takes each holder's own subcommands, tools and start work from its manager.go, so networkmanager can add its watcher and tools while systemd-networkd serves the two seat verbs as before. Builds: design 08 sign-in-page §11
73 lines
2.7 KiB
Go
73 lines
2.7 KiB
Go
// The uplink holder's tools bundle: the node-uplink seat's verbs (novox/hq ADR 0241), served by the node's
|
|
// runtime as the operator account. uplink.go is every holder's; manager.go is this holder's own, and gives the
|
|
// holder's own subcommands, tools and the work its bundle starts beside them (design 08 sign-in-page §11). stdout is
|
|
// the MCP channel; this says nothing else.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
)
|
|
|
|
// holderOwn is what a holder adds to the seat's verbs, from its manager.go: its subcommands (a process of the module
|
|
// runs one, as `uplink-tools <name>`), its own tools and the work its bundle starts once it serves.
|
|
type holderOwn struct {
|
|
Commands map[string]func(args []string) error
|
|
Tools []stdio.Tool
|
|
Start func()
|
|
}
|
|
|
|
func tools(m Machine, own holderOwn) []stdio.Tool {
|
|
return append([]stdio.Tool{
|
|
{Name: seat + ".resolvers",
|
|
Description: "The machine's resolver file as it is now: the resolvers, search domains and options it lists, " +
|
|
"whether it is the file the mesh declares, and when it is not, who wrote it as far as the machine shows " +
|
|
"— its header, a backup a VPN client left beside it, a link in its place, a known writer running. (r)",
|
|
Run: func(map[string]any) (any, error) { return m.ReadResolvers() }},
|
|
{Name: seat + ".links",
|
|
Description: "Every network link on the machine: its state, its addresses, its mac, the bridge or bond it is enslaved to (master), the link it rides on (parent: its name, or an index and namespace when that link is in another network namespace), whether the default route " +
|
|
"leaves through it, and the resolvers and search domains the network manager knows for it — a VPN's " +
|
|
"tunnel included. (r)",
|
|
Run: func(map[string]any) (any, error) { return m.Links(context.Background()) }},
|
|
}, own.Tools...)
|
|
}
|
|
|
|
// command is the holder's subcommand args name, or an error naming it when the holder has none such; nil with no args,
|
|
// which is the bundle.
|
|
func command(own holderOwn, args []string) (func(args []string) error, error) {
|
|
if len(args) == 0 {
|
|
return nil, nil
|
|
}
|
|
if run, ok := own.Commands[args[0]]; ok {
|
|
return run, nil
|
|
}
|
|
return nil, fmt.Errorf("uplink-tools has no subcommand %q", args[0])
|
|
}
|
|
|
|
func main() {
|
|
m := Machine{ResolvPath: ResolvConf, Run: execRunner, Running: running, LinkDNS: managerDNS}
|
|
own := holder(m)
|
|
run, err := command(own, os.Args[1:])
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(2)
|
|
}
|
|
if run != nil {
|
|
if err := run(os.Args[2:]); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
return
|
|
}
|
|
if own.Start != nil {
|
|
go own.Start()
|
|
}
|
|
if err := stdio.Serve("", tools(m, own)); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|