From a8a0072049fb46b2e676e9e3d87471a53ab37fe0 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 17 Jan 2018 16:33:35 -0800 Subject: [PATCH] oops need to add this moved file to git --- builder/oracle/common/ssh.go | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 builder/oracle/common/ssh.go diff --git a/builder/oracle/common/ssh.go b/builder/oracle/common/ssh.go new file mode 100644 index 000000000..aa2780128 --- /dev/null +++ b/builder/oracle/common/ssh.go @@ -0,0 +1,45 @@ +package common + +import ( + "fmt" + + packerssh "github.com/hashicorp/packer/communicator/ssh" + "github.com/mitchellh/multistep" + "golang.org/x/crypto/ssh" +) + +func CommHost(state multistep.StateBag) (string, error) { + ipAddress := state.Get("instance_ip").(string) + return ipAddress, nil +} + +// SSHConfig returns a function that can be used for the SSH communicator +// config for connecting to the instance created over SSH using the private key +// or password. +func SSHConfig(username, password string) func(state multistep.StateBag) (*ssh.ClientConfig, error) { + return func(state multistep.StateBag) (*ssh.ClientConfig, error) { + privateKey, hasKey := state.GetOk("privateKey") + if hasKey { + + signer, err := ssh.ParsePrivateKey([]byte(privateKey.(string))) + if err != nil { + return nil, fmt.Errorf("Error setting up SSH config: %s", err) + } + return &ssh.ClientConfig{ + User: username, + Auth: []ssh.AuthMethod{ssh.PublicKeys(signer)}, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), + }, nil + + } + + return &ssh.ClientConfig{ + User: username, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), + Auth: []ssh.AuthMethod{ + ssh.Password(password), + ssh.KeyboardInteractive(packerssh.PasswordKeyboardInteractive(password)), + }, + }, nil + } +}