ing
This commit is contained in:
parent
c359a7423d
commit
9a91d883d4
|
@ -88,28 +88,24 @@ func parsePrivateKey(keyPath, pw string) (ssh.Signer, error) {
|
||||||
return ssh.ParsePrivateKeyWithPassphrase(buff, []byte(pw))
|
return ssh.ParsePrivateKeyWithPassphrase(buff, []byte(pw))
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(target *ocmsc.Target) (*SSHClient, error) {
|
func New(connection *ocmsc.SensorConfigConnection) (*SSHClient, error) {
|
||||||
connection := target.Connection
|
credentials := connection.Credentials
|
||||||
auth := target.Auth
|
|
||||||
|
|
||||||
ip := connection.IP
|
ip := connection.IP
|
||||||
port, _ := cuej.NumberToInt(connection.Port)
|
port, _ := cuej.NumberToInt(connection.Port)
|
||||||
user := auth["id"].(string)
|
user := credentials["id"]
|
||||||
pw := auth["pw"].(string)
|
pw := credentials["pw"]
|
||||||
keyFilePathObj := auth["keyFilePath"]
|
keyFilePath, keyFilePathExist := credentials["keyFilePath"]
|
||||||
keyFilePath := ""
|
|
||||||
|
|
||||||
sshAuth := make([]ssh.AuthMethod, 0)
|
sshAuth := make([]ssh.AuthMethod, 0)
|
||||||
|
|
||||||
if keyFilePathObj != nil {
|
if keyFilePathExist {
|
||||||
keyFilePath = keyFilePathObj.(string)
|
|
||||||
if "" != keyFilePath {
|
if "" != keyFilePath {
|
||||||
key, err := parsePrivateKey(keyFilePath, pw)
|
key, err := parsePrivateKey(keyFilePath, pw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sshAuth = append(sshAuth, ssh.PublicKeys(key))
|
sshAuth = append(sshAuth, ssh.PublicKeys(key))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sshAuth = append(sshAuth, ssh.Password(pw))
|
sshAuth = append(sshAuth, ssh.Password(pw))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user