forked from toolshed/abra
refactor: more seamless SSH connections
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/user"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
@ -19,7 +18,7 @@ type HostConfig struct {
|
||||
}
|
||||
|
||||
// GetHostConfig retrieves a ~/.ssh/config config for a host.
|
||||
func GetHostConfig(hostname, username, port string, hasIdentityFile bool) (HostConfig, error) {
|
||||
func GetHostConfig(hostname, username, port string) (HostConfig, error) {
|
||||
var hostConfig HostConfig
|
||||
|
||||
var host, idf string
|
||||
@ -47,13 +46,12 @@ func GetHostConfig(hostname, username, port string, hasIdentityFile bool) (HostC
|
||||
}
|
||||
}
|
||||
|
||||
dummyVal := "~/.ssh/identity"
|
||||
if idf = ssh_config.Get(hostname, "IdentityFile"); (idf == dummyVal || idf == "") && hasIdentityFile {
|
||||
return hostConfig, fmt.Errorf("SSH identity file missing for %s from SSH config", hostname)
|
||||
}
|
||||
idf = ssh_config.Get(hostname, "IdentityFile")
|
||||
|
||||
hostConfig.Host = host
|
||||
hostConfig.IdentityFile = idf
|
||||
if idf != "" {
|
||||
hostConfig.IdentityFile = idf
|
||||
}
|
||||
hostConfig.Port = port
|
||||
hostConfig.User = username
|
||||
|
||||
@ -66,12 +64,7 @@ func GetHostConfig(hostname, username, port string, hasIdentityFile bool) (HostC
|
||||
func New(domainName, sshAuth, username, port string) (*simplessh.Client, error) {
|
||||
var client *simplessh.Client
|
||||
|
||||
hasIdentityFile := true
|
||||
if sshAuth == "password" {
|
||||
hasIdentityFile = false
|
||||
}
|
||||
|
||||
hostConfig, err := GetHostConfig(domainName, username, port, hasIdentityFile)
|
||||
hostConfig, err := GetHostConfig(domainName, username, port)
|
||||
if err != nil {
|
||||
return client, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user