Return error when ssh key does not exist
This commit is contained in:
parent
f2ab51a314
commit
994ceca1d1
@ -1,6 +1,7 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -71,16 +72,21 @@ func makeConfig(info *shared.SSHInfo) (*ssh.ClientConfig, error) {
|
|||||||
keyPath = expandKeyPath(keyPath)
|
keyPath = expandKeyPath(keyPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fileExists(keyPath) {
|
if !fileExists(keyPath) {
|
||||||
key, err := parsePrivateKey(keyPath)
|
return nil, errors.New("ssh public key not found at " + keyPath)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
methods = append(methods, ssh.PublicKeys(key))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
methods = append(methods, ssh.Password(info.Password))
|
// Appen public key authentication method
|
||||||
|
key, err := parsePrivateKey(keyPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
methods = append(methods, ssh.PublicKeys(key))
|
||||||
|
|
||||||
|
// Append password authentication method
|
||||||
|
if info.Password != "" {
|
||||||
|
methods = append(methods, ssh.Password(info.Password))
|
||||||
|
}
|
||||||
|
|
||||||
cfg := &ssh.ClientConfig{
|
cfg := &ssh.ClientConfig{
|
||||||
User: info.User,
|
User: info.User,
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SSHInfo contains ssh server configuration
|
||||||
type SSHInfo struct {
|
type SSHInfo struct {
|
||||||
Host string `json:"host,omitempty"`
|
Host string `json:"host,omitempty"`
|
||||||
Port string `json:"port,omitempty"`
|
Port string `json:"port,omitempty"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user