Keep the machine's forge SSH key and its keys entry (issue 955 S1)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user