builder/scaleway: support password auth

This commit is contained in:
Loïc Carr 2018-01-05 09:43:52 +01:00 committed by Matthew Hooker
parent eb56b1b70e
commit fc7d89eb79
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
1 changed files with 25 additions and 9 deletions

View File

@ -2,9 +2,10 @@ package scaleway
import (
"fmt"
"golang.org/x/crypto/ssh"
packerssh "github.com/hashicorp/packer/communicator/ssh"
"github.com/mitchellh/multistep"
"golang.org/x/crypto/ssh"
)
func commHost(state multistep.StateBag) (string, error) {
@ -14,17 +15,32 @@ func commHost(state multistep.StateBag) (string, error) {
func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
config := state.Get("config").(Config)
privateKey := state.Get("privateKey").(string)
var privateKey string
signer, err := ssh.ParsePrivateKey([]byte(privateKey))
if err != nil {
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
var auth []ssh.AuthMethod
if config.Comm.SSHPassword != "" {
auth = []ssh.AuthMethod{
ssh.Password(config.Comm.SSHPassword),
ssh.KeyboardInteractive(
packerssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)),
}
}
if config.Comm.SSHPrivateKey != "" {
if priv, ok := state.GetOk("privateKey"); ok {
privateKey = priv.(string)
}
signer, err := ssh.ParsePrivateKey([]byte(privateKey))
if err != nil {
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
}
auth = append(auth, ssh.PublicKeys(signer))
}
return &ssh.ClientConfig{
User: config.Comm.SSHUsername,
Auth: []ssh.AuthMethod{
ssh.PublicKeys(signer),
},
User: config.Comm.SSHUsername,
Auth: auth,
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}, nil
}