Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Remove fatal errors from SSH
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Watters committed Apr 26, 2020
1 parent 632fae6 commit 84a38cc
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions command/servo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"context"
"fmt"
"log"
"net"
"os"
"strings"
Expand Down Expand Up @@ -442,7 +441,7 @@ func (servoCmd *servoCommand) runInSSHSession(ctx context.Context, name string,
}
hostKeyCallback, err := knownhosts.New(knownHosts)
if err != nil {
log.Fatal("could not create hostkeycallback function: ", err)
return err
}
config := &ssh.ClientConfig{
User: servo.User,
Expand All @@ -467,35 +466,35 @@ func (servoCmd *servoCommand) runInSSHSession(ctx context.Context, name string,
// Dial the bastion host
bastionClient, err := ssh.Dial("tcp", host, bastionConfig)
if err != nil {
log.Fatal(err)
return err
}

// Establish a new connection thrrough the bastion
conn, err := bastionClient.Dial("tcp", servo.HostAndPort())
if err != nil {
log.Fatal(err)
return err
}

// Build a new SSH connection on top of the bastion connection
ncc, chans, reqs, err := ssh.NewClientConn(conn, servo.HostAndPort(), config)
if err != nil {
log.Fatal(err)
return err
}

// Now connection a client on top of it
sshClient = ssh.NewClient(ncc, chans, reqs)
} else {
sshClient, err = ssh.Dial("tcp", servo.HostAndPort(), config)
if err != nil {
log.Fatal(err)
return err
}
}
defer sshClient.Close()

// Create sesssion
session, err := sshClient.NewSession()
if err != nil {
log.Fatal("Failed to create session: ", err)
return err
}
defer session.Close()

Expand Down

0 comments on commit 84a38cc

Please sign in to comment.