This commit is contained in:
crusader 2018-07-04 12:09:14 +09:00
parent c359a7423d
commit 9a91d883d4

View File

@ -88,28 +88,24 @@ func parsePrivateKey(keyPath, pw string) (ssh.Signer, error) {
return ssh.ParsePrivateKeyWithPassphrase(buff, []byte(pw))
}
func New(target *ocmsc.Target) (*SSHClient, error) {
connection := target.Connection
auth := target.Auth
func New(connection *ocmsc.SensorConfigConnection) (*SSHClient, error) {
credentials := connection.Credentials
ip := connection.IP
port, _ := cuej.NumberToInt(connection.Port)
user := auth["id"].(string)
pw := auth["pw"].(string)
keyFilePathObj := auth["keyFilePath"]
keyFilePath := ""
user := credentials["id"]
pw := credentials["pw"]
keyFilePath, keyFilePathExist := credentials["keyFilePath"]
sshAuth := make([]ssh.AuthMethod, 0)
if keyFilePathObj != nil {
keyFilePath = keyFilePathObj.(string)
if keyFilePathExist {
if "" != keyFilePath {
key, err := parsePrivateKey(keyFilePath, pw)
if err != nil {
return nil, err
}
sshAuth = append(sshAuth, ssh.PublicKeys(key))
}
}
sshAuth = append(sshAuth, ssh.Password(pw))