github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/builder/googlecompute/ssh.go (about) 1 package googlecompute 2 3 import ( 4 "code.google.com/p/go.crypto/ssh" 5 "fmt" 6 "github.com/mitchellh/multistep" 7 ) 8 9 // sshAddress returns the ssh address. 10 func sshAddress(state multistep.StateBag) (string, error) { 11 config := state.Get("config").(*Config) 12 ipAddress := state.Get("instance_ip").(string) 13 return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil 14 } 15 16 // sshConfig returns the ssh configuration. 17 func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { 18 config := state.Get("config").(*Config) 19 privateKey := state.Get("ssh_private_key").(string) 20 21 signer, err := ssh.ParsePrivateKey([]byte(privateKey)) 22 if err != nil { 23 return nil, fmt.Errorf("Error setting up SSH config: %s", err) 24 } 25 26 return &ssh.ClientConfig{ 27 User: config.SSHUsername, 28 Auth: []ssh.AuthMethod{ 29 ssh.PublicKeys(signer), 30 }, 31 }, nil 32 }