2013-07-15 01:14:10 -04:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-05-18 15:01:44 -04:00
|
|
|
|
2015-06-09 00:34:20 -04:00
|
|
|
"golang.org/x/crypto/ssh"
|
2015-06-13 19:23:33 -04:00
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2013-07-15 01:14:10 -04:00
|
|
|
)
|
|
|
|
|
2015-06-13 19:23:33 -04:00
|
|
|
func commHost(state multistep.StateBag) (string, error) {
|
2013-08-31 15:25:08 -04:00
|
|
|
ipAddress := state.Get("droplet_ip").(string)
|
2015-06-13 19:23:33 -04:00
|
|
|
return ipAddress, nil
|
2013-07-15 01:14:10 -04:00
|
|
|
}
|
|
|
|
|
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{
|
2015-06-13 18:26:13 -04:00
|
|
|
User: config.Comm.SSHUsername,
|
2014-04-10 04:48:55 -04:00
|
|
|
Auth: []ssh.AuthMethod{
|
|
|
|
ssh.PublicKeys(signer),
|
2013-07-15 01:14:10 -04:00
|
|
|
},
|
2017-05-18 15:01:44 -04:00
|
|
|
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
2013-07-15 01:14:10 -04:00
|
|
|
}, nil
|
|
|
|
}
|