2017-09-12 11:30:39 -04:00
|
|
|
package oci
|
2017-02-13 05:35:14 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-04-07 06:20:33 -04:00
|
|
|
packerssh "github.com/hashicorp/packer/communicator/ssh"
|
2017-02-13 05:35:14 -05:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2017-08-02 12:18:53 -04:00
|
|
|
// 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 {
|
2017-02-13 05:35:14 -05:00
|
|
|
|
2017-08-02 12:18:53 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
}
|
2017-02-13 05:35:14 -05:00
|
|
|
|
2017-08-02 12:18:53 -04:00
|
|
|
return &ssh.ClientConfig{
|
|
|
|
User: username,
|
|
|
|
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
|
|
|
Auth: []ssh.AuthMethod{
|
|
|
|
ssh.Password(password),
|
|
|
|
ssh.KeyboardInteractive(packerssh.PasswordKeyboardInteractive(password)),
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
2017-02-13 05:35:14 -05:00
|
|
|
}
|