terraform/internal/communicator/ssh/password.go

29 lines
793 B
Go
Raw Normal View History

package ssh
import (
"log"
2016-04-19 02:28:46 +02:00
"golang.org/x/crypto/ssh"
)
// An implementation of ssh.KeyboardInteractiveChallenge that simply sends
// back the password for all questions. The questions are logged.
func PasswordKeyboardInteractive(password string) ssh.KeyboardInteractiveChallenge {
return func(user, instruction string, questions []string, echos []bool) ([]string, error) {
log.Printf("Keyboard interactive challenge: ")
log.Printf("-- User: %s", user)
log.Printf("-- Instructions: %s", instruction)
for i, question := range questions {
log.Printf("-- Question %d: %s", i+1, question)
}
// Just send the password back for all questions
answers := make([]string, len(questions))
2014-08-07 19:41:41 +02:00
for i := range answers {
answers[i] = string(password)
}
return answers, nil
}
}