Skip to content

Commit 35dc66e

Browse files
authored
🌱 fix usage of scp packge. (#1552)
See bramvdbogaerde/go-scp#88
1 parent 994989a commit 35dc66e

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

pkg/services/baremetal/client/ssh/ssh_client.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,11 @@ func IsTimeoutError(err error) bool {
665665
return strings.Contains(err.Error(), ErrTimeout.Error())
666666
}
667667

668-
func (c *sshClient) getSSHClient() (*ssh.Client, *ssh.ClientConfig, error) {
668+
func (c *sshClient) getSSHClient() (*ssh.Client, error) {
669669
// Create the Signer for this private key.
670670
signer, err := ssh.ParsePrivateKey([]byte(c.privateSSHKey))
671671
if err != nil {
672-
return nil, nil, fmt.Errorf("unable to parse private key: %w", err)
672+
return nil, fmt.Errorf("unable to parse private key: %w", err)
673673
}
674674

675675
config := &ssh.ClientConfig{
@@ -685,14 +685,14 @@ func (c *sshClient) getSSHClient() (*ssh.Client, *ssh.ClientConfig, error) {
685685
// Connect to the remote server and perform the SSH handshake.
686686
client, err := ssh.Dial("tcp", fmt.Sprintf("%s:%v", c.ip, c.port), config)
687687
if err != nil {
688-
return nil, nil, fmt.Errorf("failed to dial ssh. Error message: %s. DialErr: %w", err.Error(), errSSHDialFailed)
688+
return nil, fmt.Errorf("failed to dial ssh. Error message: %s. DialErr: %w", err.Error(), errSSHDialFailed)
689689
}
690690

691-
return client, config, nil
691+
return client, nil
692692
}
693693

694694
func (c *sshClient) runSSH(command string) Output {
695-
client, _, err := c.getSSHClient()
695+
client, err := c.getSSHClient()
696696
if err != nil {
697697
return Output{Err: err}
698698
}
@@ -767,7 +767,7 @@ func removeUselessLinesFromCloudInitOutput(s string) string {
767767
}
768768

769769
func (c *sshClient) ExecutePreProvisionCommand(ctx context.Context, command string) (int, string, error) {
770-
client, clientConfig, err := c.getSSHClient()
770+
client, err := c.getSSHClient()
771771
if err != nil {
772772
return 0, "", err
773773
}
@@ -780,14 +780,6 @@ func (c *sshClient) ExecutePreProvisionCommand(ctx context.Context, command stri
780780

781781
defer scpClient.Close()
782782

783-
scpClient.ClientConfig = clientConfig
784-
scpClient.Host = fmt.Sprintf("%s:%d", c.ip, c.port)
785-
786-
err = scpClient.Connect()
787-
if err != nil {
788-
return 0, "", fmt.Errorf("couldn't establish a connection to the remote server: %w ", err)
789-
}
790-
791783
f, err := os.Open(command) //nolint:gosec // the variable was valided.
792784
if err != nil {
793785
return 0, "", fmt.Errorf("error opening file %q: %w", command, err)

0 commit comments

Comments
 (0)