github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/oracle/oci/ssh.go (about) 1 package oci 2 3 import ( 4 "fmt" 5 6 packerssh "github.com/hashicorp/packer/communicator/ssh" 7 "github.com/mitchellh/multistep" 8 "golang.org/x/crypto/ssh" 9 ) 10 11 func commHost(state multistep.StateBag) (string, error) { 12 ipAddress := state.Get("instance_ip").(string) 13 return ipAddress, nil 14 } 15 16 // SSHConfig returns a function that can be used for the SSH communicator 17 // config for connecting to the instance created over SSH using the private key 18 // or password. 19 func SSHConfig(username, password string) func(state multistep.StateBag) (*ssh.ClientConfig, error) { 20 return func(state multistep.StateBag) (*ssh.ClientConfig, error) { 21 privateKey, hasKey := state.GetOk("privateKey") 22 if hasKey { 23 24 signer, err := ssh.ParsePrivateKey([]byte(privateKey.(string))) 25 if err != nil { 26 return nil, fmt.Errorf("Error setting up SSH config: %s", err) 27 } 28 return &ssh.ClientConfig{ 29 User: username, 30 Auth: []ssh.AuthMethod{ssh.PublicKeys(signer)}, 31 HostKeyCallback: ssh.InsecureIgnoreHostKey(), 32 }, nil 33 34 } 35 36 return &ssh.ClientConfig{ 37 User: username, 38 HostKeyCallback: ssh.InsecureIgnoreHostKey(), 39 Auth: []ssh.AuthMethod{ 40 ssh.Password(password), 41 ssh.KeyboardInteractive(packerssh.PasswordKeyboardInteractive(password)), 42 }, 43 }, nil 44 } 45 }