34 lines
917 B
Go
34 lines
917 B
Go
package common
|
|
|
|
import (
|
|
gossh "code.google.com/p/go.crypto/ssh"
|
|
"fmt"
|
|
"github.com/mitchellh/goamz/ec2"
|
|
"github.com/mitchellh/packer/communicator/ssh"
|
|
)
|
|
|
|
func SSHAddress(port int) func(map[string]interface{}) (string, error) {
|
|
return func(state map[string]interface{}) (string, error) {
|
|
instance := state["instance"].(*ec2.Instance)
|
|
return fmt.Sprintf("%s:%d", instance.DNSName, port), nil
|
|
}
|
|
}
|
|
|
|
func SSHConfig(username string) func(map[string]interface{}) (*gossh.ClientConfig, error) {
|
|
return func(state map[string]interface{}) (*gossh.ClientConfig, error) {
|
|
privateKey := state["privateKey"].(string)
|
|
|
|
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: username,
|
|
Auth: []gossh.ClientAuth{
|
|
gossh.ClientAuthKeyring(keyring),
|
|
},
|
|
}, nil
|
|
}
|
|
}
|