diff --git a/vendor/github.com/appleboy/easyssh-proxy/easyssh.go b/vendor/github.com/appleboy/easyssh-proxy/easyssh.go index 80be120..de50948 100644 --- a/vendor/github.com/appleboy/easyssh-proxy/easyssh.go +++ b/vendor/github.com/appleboy/easyssh-proxy/easyssh.go @@ -67,7 +67,12 @@ func getKeyFile(keypath string) (ssh.Signer, error) { return pubkey, nil } -func getSSHConfig(config DefaultConfig) *ssh.ClientConfig { +// returns *ssh.ClientConfig and io.Closer. +// if io.Closer is not nil, io.Closer.Close() should be called when +// *ssh.ClientConfig is no longer used. +func getSSHConfig(config DefaultConfig) (*ssh.ClientConfig, io.Closer) { + var sshAgent io.Closer + // auths holds the detected ssh auth methods auths := []ssh.AuthMethod{} @@ -93,7 +98,6 @@ func getSSHConfig(config DefaultConfig) *ssh.ClientConfig { if sshAgent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")); err == nil { auths = append(auths, ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers)) - defer sshAgent.Close() } return &ssh.ClientConfig{ @@ -101,7 +105,7 @@ func getSSHConfig(config DefaultConfig) *ssh.ClientConfig { User: config.User, Auth: auths, HostKeyCallback: ssh.InsecureIgnoreHostKey(), - } + }, sshAgent } // Connect to remote server using MakeConfig struct and returns *ssh.Session @@ -109,23 +113,29 @@ func (ssh_conf *MakeConfig) Connect() (*ssh.Session, error) { var client *ssh.Client var err error - targetConfig := getSSHConfig(DefaultConfig{ + targetConfig, closer := getSSHConfig(DefaultConfig{ User: ssh_conf.User, Key: ssh_conf.Key, KeyPath: ssh_conf.KeyPath, Password: ssh_conf.Password, Timeout: ssh_conf.Timeout, }) + if closer != nil { + defer closer.Close() + } // Enable proxy command if ssh_conf.Proxy.Server != "" { - proxyConfig := getSSHConfig(DefaultConfig{ + proxyConfig, closer := getSSHConfig(DefaultConfig{ User: ssh_conf.Proxy.User, Key: ssh_conf.Proxy.Key, KeyPath: ssh_conf.Proxy.KeyPath, Password: ssh_conf.Proxy.Password, Timeout: ssh_conf.Proxy.Timeout, }) + if closer != nil { + defer closer.Close() + } proxyClient, err := ssh.Dial("tcp", net.JoinHostPort(ssh_conf.Proxy.Server, ssh_conf.Proxy.Port), proxyConfig) if err != nil {