2013-07-15 01:14:10 -04:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
2015-04-04 01:30:13 -04:00
|
|
|
"golang.org/x/crypto/ssh"
|
2013-07-15 01:14:10 -04:00
|
|
|
"fmt"
|
2013-08-31 15:25:08 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2013-07-15 01:14:10 -04:00
|
|
|
)
|
|
|
|
|
2013-08-31 15:25:08 -04:00
|
|
|
func sshAddress(state multistep.StateBag) (string, error) {
|
2015-05-27 15:50:43 -04:00
|
|
|
config := state.Get("config").(Config)
|
2013-08-31 15:25:08 -04:00
|
|
|
ipAddress := state.Get("droplet_ip").(string)
|
2013-07-15 01:14:10 -04:00
|
|
|
return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil
|
|
|
|
}
|
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
|
2015-05-27 15:50:43 -04:00
|
|
|
config := state.Get("config").(Config)
|
2013-08-31 15:25:08 -04:00
|
|
|
privateKey := state.Get("privateKey").(string)
|
2013-07-15 01:14:10 -04:00
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
signer, err := ssh.ParsePrivateKey([]byte(privateKey))
|
|
|
|
if err != nil {
|
2013-07-15 01:14:10 -04:00
|
|
|
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
|
|
|
|
}
|
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
return &ssh.ClientConfig{
|
2013-07-15 01:14:10 -04:00
|
|
|
User: config.SSHUsername,
|
2014-04-10 04:48:55 -04:00
|
|
|
Auth: []ssh.AuthMethod{
|
|
|
|
ssh.PublicKeys(signer),
|
2013-07-15 01:14:10 -04:00
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|