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