jszwedko b1497b951c code.google.com/p/go.crypto/ssh -> golang.org/x/crypto/ssh
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.
2015-05-28 08:17:49 -07:00

33 lines
829 B
Go

package googlecompute
import (
"golang.org/x/crypto/ssh"
"fmt"
"github.com/mitchellh/multistep"
)
// sshAddress returns the ssh address.
func sshAddress(state multistep.StateBag) (string, error) {
config := state.Get("config").(*Config)
ipAddress := state.Get("instance_ip").(string)
return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil
}
// sshConfig returns the ssh configuration.
func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
config := state.Get("config").(*Config)
privateKey := state.Get("ssh_private_key").(string)
signer, err := ssh.ParsePrivateKey([]byte(privateKey))
if err != nil {
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
}
return &ssh.ClientConfig{
User: config.SSHUsername,
Auth: []ssh.AuthMethod{
ssh.PublicKeys(signer),
},
}, nil
}