helper: communicator.SSHFileSigner => ssh.FileSigner

* had to to avoid circular dependency
* this commit fixes #6631 ( esxi cannot be reached by ssh )
This commit is contained in:
Adrien Delorme 2018-08-27 16:13:15 +02:00
parent b83c72fd54
commit 5369c15459
4 changed files with 9 additions and 6 deletions

View File

@ -17,6 +17,7 @@ import (
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
"github.com/hashicorp/packer/communicator/ssh"
"github.com/hashicorp/packer/helper/multistep"
helperssh "github.com/hashicorp/packer/helper/ssh"
"github.com/hashicorp/packer/packer"
gossh "golang.org/x/crypto/ssh"
)
@ -514,7 +515,7 @@ func (d *ESX5Driver) connect() error {
}
if d.PrivateKey != "" {
signer, err := gossh.ParsePrivateKey([]byte(d.PrivateKey))
signer, err := helperssh.FileSigner(d.PrivateKey)
if err != nil {
return err
}

View File

@ -10,6 +10,7 @@ import (
packerssh "github.com/hashicorp/packer/communicator/ssh"
"github.com/hashicorp/packer/helper/multistep"
helperssh "github.com/hashicorp/packer/helper/ssh"
"github.com/hashicorp/packer/template/interpolate"
"github.com/masterzen/winrm"
"golang.org/x/crypto/ssh"
@ -241,7 +242,7 @@ func (c *Config) prepareSSH(ctx *interpolate.Context) []error {
if _, err := os.Stat(c.SSHPrivateKeyFile); err != nil {
errs = append(errs, fmt.Errorf(
"ssh_private_key_file is invalid: %s", err))
} else if _, err := SSHFileSigner(c.SSHPrivateKeyFile); err != nil {
} else if _, err := helperssh.FileSigner(c.SSHPrivateKeyFile); err != nil {
errs = append(errs, fmt.Errorf(
"ssh_private_key_file is invalid: %s", err))
}

View File

@ -12,6 +12,7 @@ import (
"github.com/hashicorp/packer/communicator/ssh"
"github.com/hashicorp/packer/helper/multistep"
helperssh "github.com/hashicorp/packer/helper/ssh"
"github.com/hashicorp/packer/packer"
gossh "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
@ -225,7 +226,7 @@ func sshBastionConfig(config *Config) (*gossh.ClientConfig, error) {
}
if config.SSHBastionPrivateKey != "" {
signer, err := gossh.ParsePrivateKey([]byte(config.SSHBastionPrivateKey))
signer, err := helperssh.FileSigner(config.SSHBastionPrivateKey)
if err != nil {
return nil, err
}

View File

@ -1,4 +1,4 @@
package communicator
package ssh
import (
"encoding/pem"
@ -9,8 +9,8 @@ import (
"golang.org/x/crypto/ssh"
)
// SSHFileSigner returns an ssh.Signer for a key file.
func SSHFileSigner(path string) (ssh.Signer, error) {
// FileSigner returns an ssh.Signer for a key file.
func FileSigner(path string) (ssh.Signer, error) {
f, err := os.Open(path)
if err != nil {
return nil, err