code.google.com/p/go.crypto/ssh is now at golang.org/x/crypto/ssh as of https://code.google.com/p/go/source/detail?spec=svn.crypto.69e2a90ed92d03812364aeb947b7068dc42e561e&repo=crypto&r=8fec09c61d5d66f460d227fd1df3473d7e015bc6 Using the code.google.com import redirects properly, but runs into issues if you try to use a subpackage of `ssh`, e.g. `agent` which refers to golang.org/x/crypto/ssh causing conflicts if your types expect code.google.com/p/go.crypto/ssh. This is a precursor to a PR for #1066.
40 lines
965 B
Go
40 lines
965 B
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
gossh "golang.org/x/crypto/ssh"
|
|
"github.com/mitchellh/multistep"
|
|
commonssh "github.com/mitchellh/packer/common/ssh"
|
|
"github.com/mitchellh/packer/communicator/ssh"
|
|
)
|
|
|
|
func SSHAddress(state multistep.StateBag) (string, error) {
|
|
sshHostPort := state.Get("sshHostPort").(uint)
|
|
return fmt.Sprintf("127.0.0.1:%d", sshHostPort), nil
|
|
}
|
|
|
|
func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*gossh.ClientConfig, error) {
|
|
return func(state multistep.StateBag) (*gossh.ClientConfig, error) {
|
|
auth := []gossh.AuthMethod{
|
|
gossh.Password(config.SSHPassword),
|
|
gossh.KeyboardInteractive(
|
|
ssh.PasswordKeyboardInteractive(config.SSHPassword)),
|
|
}
|
|
|
|
if config.SSHKeyPath != "" {
|
|
signer, err := commonssh.FileSigner(config.SSHKeyPath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
auth = append(auth, gossh.PublicKeys(signer))
|
|
}
|
|
|
|
return &gossh.ClientConfig{
|
|
User: config.SSHUser,
|
|
Auth: auth,
|
|
}, nil
|
|
}
|
|
}
|