github.com/alouche/packer@v0.3.7/builder/digitalocean/ssh.go (about) 1 package digitalocean 2 3 import ( 4 gossh "code.google.com/p/go.crypto/ssh" 5 "fmt" 6 "github.com/mitchellh/multistep" 7 "github.com/mitchellh/packer/communicator/ssh" 8 ) 9 10 func sshAddress(state multistep.StateBag) (string, error) { 11 config := state.Get("config").(config) 12 ipAddress := state.Get("droplet_ip").(string) 13 return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil 14 } 15 16 func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) { 17 config := state.Get("config").(config) 18 privateKey := state.Get("privateKey").(string) 19 20 keyring := new(ssh.SimpleKeychain) 21 if err := keyring.AddPEMKey(privateKey); err != nil { 22 return nil, fmt.Errorf("Error setting up SSH config: %s", err) 23 } 24 25 return &gossh.ClientConfig{ 26 User: config.SSHUsername, 27 Auth: []gossh.ClientAuth{ 28 gossh.ClientAuthKeyring(keyring), 29 }, 30 }, nil 31 }