]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
rpc: use SSHConfig struct as argument to DialSSH()
authorSimon Ruderich <simon@ruderich.org>
Tue, 18 May 2021 08:10:09 +0000 (10:10 +0200)
committerSimon Ruderich <simon@ruderich.org>
Tue, 18 May 2021 08:10:09 +0000 (10:10 +0200)
In preparation to add more arguments to DialSSH().

cmd/safcm/sync.go
rpc/dial.go

index 6f38daf37d100713fa00340b4aa54321944cd4a8..6fe65fae326c2b09fa74b51202a964afb44a11ce 100644 (file)
@@ -374,7 +374,11 @@ func (s *Sync) Host(wg *sync.WaitGroup) error {
        if user == "" {
                user = s.config.SshUser
        }
-       err := conn.DialSSH(user, s.host.Name, s.config.SshConfig)
+       err := conn.DialSSH(rpc.SSHConfig{
+               Host:      s.host.Name,
+               User:      user,
+               SshConfig: s.config.SshConfig,
+       })
        if err != nil {
                return err
        }
index caa34b098fe933ca9fba22d7f0ea35aadb05d33a..c0c6cd4088b2859d758aa0d06cf64405a2b70a16 100644 (file)
@@ -32,14 +32,20 @@ import (
        "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
+}
+
+func (c *Conn) DialSSH(cfg SSHConfig) error {
        if c.events == nil {
                return fmt.Errorf("cannot reuse Conn")
        }
 
-       remote := host
-       if user != "" {
-               remote = user + "@" + host
+       remote := cfg.Host
+       if cfg.User != "" {
+               remote = cfg.User + "@" + cfg.Host
        }
        c.debugf("DialSSH: connecting to %q", remote)
 
@@ -50,8 +56,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...),