github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/builder/oracle/common/ssh.go (about) 1 package common 2 3 import ( 4 "fmt" 5 6 packerssh "github.com/hashicorp/packer/communicator/ssh" 7 "github.com/hashicorp/packer/helper/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 }