2013-12-08 17:37:36 -05:00
|
|
|
package googlecompute
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/multistep"
|
2015-06-09 00:34:20 -04:00
|
|
|
"golang.org/x/crypto/ssh"
|
2013-12-08 17:37:36 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// sshAddress returns the ssh address.
|
|
|
|
func sshAddress(state multistep.StateBag) (string, error) {
|
2013-12-12 19:41:44 -05:00
|
|
|
config := state.Get("config").(*Config)
|
2013-12-08 17:37:36 -05:00
|
|
|
ipAddress := state.Get("instance_ip").(string)
|
|
|
|
return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// sshConfig returns the ssh configuration.
|
2014-04-10 04:48:55 -04:00
|
|
|
func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
|
2013-12-12 19:41:44 -05:00
|
|
|
config := state.Get("config").(*Config)
|
2013-12-08 17:37:36 -05:00
|
|
|
privateKey := state.Get("ssh_private_key").(string)
|
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
signer, err := ssh.ParsePrivateKey([]byte(privateKey))
|
|
|
|
if err != nil {
|
2013-12-08 17:37:36 -05:00
|
|
|
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
|
|
|
|
}
|
2013-12-13 21:06:49 -05:00
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
return &ssh.ClientConfig{
|
2013-12-08 17:37:36 -05:00
|
|
|
User: config.SSHUsername,
|
2014-04-10 04:48:55 -04:00
|
|
|
Auth: []ssh.AuthMethod{
|
|
|
|
ssh.PublicKeys(signer),
|
|
|
|
},
|
|
|
|
}, nil
|
2013-12-08 17:37:36 -05:00
|
|
|
}
|