From 8a3f6af248e28ea7efc1bf89751a597d28834942 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 18 May 2021 10:10:09 +0200 Subject: [PATCH] rpc: use SSHConfig struct as argument to DialSSH() In preparation to add more arguments to DialSSH(). --- cmd/safcm/sync.go | 6 +++++- rpc/dial.go | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cmd/safcm/sync.go b/cmd/safcm/sync.go index 6f38daf..6fe65fa 100644 --- a/cmd/safcm/sync.go +++ b/cmd/safcm/sync.go @@ -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 } diff --git a/rpc/dial.go b/rpc/dial.go index caa34b0..c0c6cd4 100644 --- a/rpc/dial.go +++ b/rpc/dial.go @@ -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...), -- 2.43.2