X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=rpc%2Fdial.go;h=e4d7f3842c90b67b6d4c69ad599c980573f45271;hb=791f34212ebd19a9c79c9bd1157f590f4b24f5c2;hp=caa34b098fe933ca9fba22d7f0ea35aadb05d33a;hpb=35e775270d3df86a5801c4905e98e562d2dd5ec6;p=safcm%2Fsafcm.git diff --git a/rpc/dial.go b/rpc/dial.go index caa34b0..e4d7f38 100644 --- a/rpc/dial.go +++ b/rpc/dial.go @@ -1,6 +1,6 @@ // Simple RPC-like protocol: establish new connection and upload helper -// Copyright (C) 2021 Simon Ruderich +// Copyright (C) 2021-2022 Simon Ruderich // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -24,22 +24,35 @@ import ( "encoding/hex" "fmt" "io" + "io/fs" "os/exec" "strconv" "strings" "ruderich.org/simon/safcm" - "ruderich.org/simon/safcm/remote" ) -func (c *Conn) DialSSH(user, host, sshConfig string) error { +type SSHConfig struct { + Host string + User string // optional + SshConfig string // optional + + RemoteHelpers fs.FS +} + +func (c *Conn) DialSSH(cfg SSHConfig) error { if c.events == nil { return fmt.Errorf("cannot reuse Conn") } - remote := host - if user != "" { - remote = user + "@" + host + if cfg.RemoteHelpers == nil { + return fmt.Errorf("SSHConfig.RemoteHelpers not set") + } + c.remoteHelpers = cfg.RemoteHelpers + + remote := cfg.Host + if cfg.User != "" { + remote = cfg.User + "@" + cfg.Host } c.debugf("DialSSH: connecting to %q", remote) @@ -50,8 +63,8 @@ func (c *Conn) DialSSH(user, host, sshConfig string) error { } c.sshRemote = remote - if sshConfig != "" { - c.sshOpts = []string{"-F", sshConfig} + if cfg.SshConfig != "" { + c.sshOpts = []string{"-F", cfg.SshConfig} } c.cmd = exec.Command("ssh", append(append([]string{}, c.sshOpts...), @@ -77,7 +90,7 @@ func (c *Conn) DialSSH(user, host, sshConfig string) error { err = c.dialSSH(stdin, stdout) if err != nil { - c.Kill() + c.Kill() //nolint:errcheck return err } c.conn = safcm.NewGobConn(stdout, stdin) @@ -202,9 +215,9 @@ f return err } - // Get embedded helper binary - helper, err := remote.Helpers.ReadFile( - fmt.Sprintf("helpers/%s-%s", goos, goarch)) + // Get remote helper binary + helper, err := fs.ReadFile(c.remoteHelpers, + fmt.Sprintf("%s-%s", goos, goarch)) if err != nil { return fmt.Errorf("remote not built for GOOS/GOARCH %s/%s", goos, goarch)