packer-cn/builder/digitalocean/ssh.go

31 lines
663 B
Go
Raw Normal View History

package digitalocean
import (
"fmt"
2015-06-09 00:34:20 -04:00
"golang.org/x/crypto/ssh"
"github.com/mitchellh/multistep"
)
func commHost(state multistep.StateBag) (string, error) {
ipAddress := state.Get("droplet_ip").(string)
return ipAddress, nil
}
func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
config := state.Get("config").(Config)
privateKey := state.Get("privateKey").(string)
signer, err := ssh.ParsePrivateKey([]byte(privateKey))
if err != nil {
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
}
return &ssh.ClientConfig{
2015-06-13 18:26:13 -04:00
User: config.Comm.SSHUsername,
Auth: []ssh.AuthMethod{
ssh.PublicKeys(signer),
},
}, nil
}