packer-cn/builder/virtualbox/common/ssh.go

42 lines
1.0 KiB
Go
Raw Normal View History

2013-12-22 12:08:09 -05:00
package common
import (
"github.com/mitchellh/multistep"
commonssh "github.com/mitchellh/packer/common/ssh"
2013-12-22 12:08:09 -05:00
"github.com/mitchellh/packer/communicator/ssh"
2015-06-09 00:34:20 -04:00
gossh "golang.org/x/crypto/ssh"
2013-12-22 12:08:09 -05:00
)
func CommHost(state multistep.StateBag) (string, error) {
return "127.0.0.1", nil
}
func SSHPort(state multistep.StateBag) (int, error) {
2013-12-22 12:08:09 -05:00
sshHostPort := state.Get("sshHostPort").(uint)
return int(sshHostPort), nil
2013-12-22 12:08:09 -05:00
}
func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*gossh.ClientConfig, error) {
return func(state multistep.StateBag) (*gossh.ClientConfig, error) {
auth := []gossh.AuthMethod{
gossh.Password(config.Comm.SSHPassword),
gossh.KeyboardInteractive(
ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)),
2013-12-22 12:08:09 -05:00
}
if config.SSHKeyPath != "" {
signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey)
2013-12-22 12:08:09 -05:00
if err != nil {
return nil, err
}
2014-04-26 14:12:43 -04:00
auth = append(auth, gossh.PublicKeys(signer))
2013-12-22 12:08:09 -05:00
}
return &gossh.ClientConfig{
User: config.Comm.SSHUsername,
2013-12-22 12:08:09 -05:00
Auth: auth,
}, nil
}
}