2013-07-15 01:14:10 -04:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
|
|
|
gossh "code.google.com/p/go.crypto/ssh"
|
|
|
|
"fmt"
|
2013-08-31 15:25:08 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2013-07-15 01:14:10 -04:00
|
|
|
"github.com/mitchellh/packer/communicator/ssh"
|
|
|
|
)
|
|
|
|
|
2013-08-31 15:25:08 -04:00
|
|
|
func sshAddress(state multistep.StateBag) (string, error) {
|
|
|
|
config := state.Get("config").(config)
|
|
|
|
ipAddress := state.Get("droplet_ip").(string)
|
2013-07-15 01:14:10 -04:00
|
|
|
return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil
|
|
|
|
}
|
|
|
|
|
2013-08-31 15:25:08 -04:00
|
|
|
func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) {
|
|
|
|
config := state.Get("config").(config)
|
|
|
|
privateKey := state.Get("privateKey").(string)
|
2013-07-15 01:14:10 -04:00
|
|
|
|
|
|
|
keyring := new(ssh.SimpleKeychain)
|
|
|
|
if err := keyring.AddPEMKey(privateKey); err != nil {
|
|
|
|
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &gossh.ClientConfig{
|
|
|
|
User: config.SSHUsername,
|
|
|
|
Auth: []gossh.ClientAuth{
|
|
|
|
gossh.ClientAuthKeyring(keyring),
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|