Skip to content

Commit 55f5a6a

Browse files
committed
chore: NewSSHClient
Signed-off-by: Javier Aliaga <javier@diagrid.io>
1 parent 2501818 commit 55f5a6a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

bindings/sftp/client.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ func newClient(address string, config *ssh.ClientConfig) (*Client, error) {
4040
return nil, errors.New("sftp binding error: client not initialized")
4141
}
4242

43-
sshClient, err := ssh.Dial("tcp", address, config)
43+
sshClient, err := newSshClient(address, config)
4444
if err != nil {
45-
return nil, fmt.Errorf("sftp binding error: error create ssh client: %w", err)
45+
return nil, err
4646
}
4747

4848
newSftpClient, err := sftpClient.NewClient(sshClient)
@@ -213,9 +213,9 @@ func doReconnect(c *Client) error {
213213
return nil
214214
}
215215

216-
sshClient, err := ssh.Dial("tcp", c.address, c.config)
216+
sshClient, err := newSshClient(c.address, c.config)
217217
if err != nil {
218-
return fmt.Errorf("sftp binding error: error create ssh client: %w", err)
218+
return err
219219
}
220220

221221
newSftpClient, err := sftpClient.NewClient(sshClient)
@@ -242,6 +242,14 @@ func doReconnect(c *Client) error {
242242
return nil
243243
}
244244

245+
func newSshClient(address string, config *ssh.ClientConfig) (*ssh.Client, error) {
246+
sshClient, err := ssh.Dial("tcp", address, config)
247+
if err != nil {
248+
return nil, fmt.Errorf("sftp binding error: error create ssh client: %w", err)
249+
}
250+
return sshClient, nil
251+
}
252+
245253
// shouldReconnect returns true if the error looks like a transport-level failure
246254
func shouldReconnect(err error) bool {
247255
if err == nil {

0 commit comments

Comments
 (0)