github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/builder/digitalocean/ssh.go (about)

     1  package digitalocean
     2  
     3  import (
     4  	gossh "code.google.com/p/go.crypto/ssh"
     5  	"fmt"
     6  	"github.com/mitchellh/packer/communicator/ssh"
     7  )
     8  
     9  func sshAddress(state map[string]interface{}) (string, error) {
    10  	config := state["config"].(config)
    11  	ipAddress := state["droplet_ip"].(string)
    12  	return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil
    13  }
    14  
    15  func sshConfig(state map[string]interface{}) (*gossh.ClientConfig, error) {
    16  	config := state["config"].(config)
    17  	privateKey := state["privateKey"].(string)
    18  
    19  	keyring := new(ssh.SimpleKeychain)
    20  	if err := keyring.AddPEMKey(privateKey); err != nil {
    21  		return nil, fmt.Errorf("Error setting up SSH config: %s", err)
    22  	}
    23  
    24  	return &gossh.ClientConfig{
    25  		User: config.SSHUsername,
    26  		Auth: []gossh.ClientAuth{
    27  			gossh.ClientAuthKeyring(keyring),
    28  		},
    29  	}, nil
    30  }