Keep the machine's forge SSH key and its keys entry (issue 955 S1)

This commit is contained in:
fix-955-ssh
2026-10-16 22:43:18 +02:00
parent 017b729bc9
commit b2009f1bb5
5 changed files with 281 additions and 1 deletions
@@ -10,12 +10,15 @@ import (
"fmt"
"math"
"os"
"os/user"
"strings"
"time"
stdio "git.novox.be/novox/mesh-sdk/go"
)
func main() {
go startKeeper()
// An empty name serves as the module the runtime names (MESH_SERVED_MODULE): ssh-client.
if err := stdio.Serve("", tools(NewClient())); err != nil {
fmt.Fprintln(os.Stderr, err)
@@ -136,3 +139,23 @@ func flag(args map[string]any, key string, def bool) bool {
}
return def
}
// startKeeper runs the forge key's keeper (keykeeper.go) when the runtime launched this process for a node:
// outside a launch — a build, a check — there is no state to put the entry in.
func startKeeper() {
node := strings.TrimSpace(os.Getenv("MESH_NODE"))
c := NewClient()
u, err := user.Current()
if node == "" || err != nil || c.Home == "" {
return
}
k := &KeyKeeper{Home: c.Home, Node: node, Account: u.Username, Run: ExecRunner, State: keysState{}, Now: time.Now}
k.Keep(context.Background(), func(f string, a ...any) { fmt.Fprintf(os.Stderr, "[ssh-client] "+f+"\n", a...) })
}
type keysState struct{}
func (keysState) Put(key string, value any) error {
_, err := stdio.State("keys").Put(key, value)
return err
}