From e89df5c408350476c5d38d3ba44e630fa51ea795 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Fri, 29 Sep 2023 11:25:19 +0300 Subject: [PATCH] Use passed-in AuthMethods in rigtest Signed-off-by: Kimmo Lehto --- cmd/rigtest/rigtest.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/cmd/rigtest/rigtest.go b/cmd/rigtest/rigtest.go index d8bcb33c..6713b767 100644 --- a/cmd/rigtest/rigtest.go +++ b/cmd/rigtest/rigtest.go @@ -156,10 +156,9 @@ func main() { port = p } - var h *Host switch *proto { case "ssh": - h = &Host{ + hosts = append(hosts, &Host{ Connection: rig.Connection{ SSH: &rig.SSH{ Address: address, @@ -169,9 +168,27 @@ func main() { PasswordCallback: passfunc, }, }, + }) + // use a key from memory + key, err := goos.ReadFile(*kp) + if err != nil { + panic(err) } + authMethods, err := rig.ParseSSHPrivateKey(key, rig.DefaultPasswordCallback) + hosts = append(hosts, &Host{ + Connection: rig.Connection{ + SSH: &rig.SSH{ + Address: address, + Port: port, + User: *usr, + KeyPath: nil, + PasswordCallback: passfunc, + AuthMethods: authMethods, + }, + }, + }) case "winrm": - h = &Host{ + hosts = append(hosts, &Host{ Connection: rig.Connection{ WinRM: &rig.WinRM{ Address: *dh, @@ -182,19 +199,18 @@ func main() { Password: *pwd, }, }, - } + }) case "localhost": - h = &Host{ + hosts = append(hosts, &Host{ Connection: rig.Connection{ Localhost: &rig.Localhost{ Enabled: true, }, }, - } + }) default: panic("unknown protocol " + *proto) } - hosts = append(hosts, h) } t := testRunner{}