2013-12-08 17:37:36 -05:00
|
|
|
package googlecompute
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-06-13 19:23:33 -04:00
|
|
|
|
2013-12-08 17:37:36 -05:00
|
|
|
"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
|
|
|
)
|
|
|
|
|
2015-06-13 19:23:33 -04:00
|
|
|
func commHost(state multistep.StateBag) (string, error) {
|
2013-12-08 17:37:36 -05:00
|
|
|
ipAddress := state.Get("instance_ip").(string)
|
2015-06-13 19:23:33 -04:00
|
|
|
return ipAddress, nil
|
2013-12-08 17:37:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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{
|
2015-06-13 18:30:16 -04:00
|
|
|
User: config.Comm.SSHUsername,
|
2014-04-10 04:48:55 -04:00
|
|
|
Auth: []ssh.AuthMethod{
|
|
|
|
ssh.PublicKeys(signer),
|
|
|
|
},
|
|
|
|
}, nil
|
2013-12-08 17:37:36 -05:00
|
|
|
}
|