From a72ec1ae8dc520af63e2e8e168908cc97e34f9ee Mon Sep 17 00:00:00 2001 From: Vladislav Rassokhin Date: Mon, 8 Jul 2019 18:40:01 +0300 Subject: [PATCH] Reuse library function for SSH provisioner config --- clone/builder.go | 2 +- common/config_ssh.go | 39 --------------------------------------- go.mod | 1 - go.sum | 3 +-- iso/builder.go | 2 +- 5 files changed, 3 insertions(+), 44 deletions(-) diff --git a/clone/builder.go b/clone/builder.go index ac446733b..008472296 100644 --- a/clone/builder.go +++ b/clone/builder.go @@ -62,7 +62,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &communicator.StepConnect{ Config: &b.config.Comm, Host: common.CommHost(b.config.Comm.SSHHost), - SSHConfig: common.SshConfig, + SSHConfig: b.config.Comm.SSHConfigFunc(), }, &packerCommon.StepProvision{}, &common.StepShutdown{ diff --git a/common/config_ssh.go b/common/config_ssh.go index e1df13e54..d4104a4e8 100644 --- a/common/config_ssh.go +++ b/common/config_ssh.go @@ -1,12 +1,7 @@ package common import ( - "fmt" - packerssh "github.com/hashicorp/packer/communicator/ssh" - "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/multistep" - "golang.org/x/crypto/ssh" - "io/ioutil" ) func CommHost(host string) func(multistep.StateBag) (string, error) { @@ -18,37 +13,3 @@ func CommHost(host string) func(multistep.StateBag) (string, error) { } } } - -func SshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { - comm := state.Get("comm").(*communicator.Config) - - var auth []ssh.AuthMethod - - if comm.SSHPrivateKeyFile != "" { - privateKey, err := ioutil.ReadFile(comm.SSHPrivateKeyFile) - if err != nil { - return nil, fmt.Errorf("Error loading configured private key file: %s", err) - } - - signer, err := ssh.ParsePrivateKey(privateKey) - if err != nil { - return nil, fmt.Errorf("Error setting up SSH config: %s", err) - } - - auth = []ssh.AuthMethod{ssh.PublicKeys(signer)} - } else { - auth = []ssh.AuthMethod{ - ssh.Password(comm.SSHPassword), - ssh.KeyboardInteractive( - packerssh.PasswordKeyboardInteractive(comm.SSHPassword)), - } - } - - clientConfig := &ssh.ClientConfig{ - User: comm.SSHUsername, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - } - clientConfig.Auth = auth - - return clientConfig, nil -} diff --git a/go.mod b/go.mod index d00a4a152..10057c4fb 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,5 @@ module github.com/jetbrains-infra/packer-builder-vsphere require ( github.com/hashicorp/packer v1.4.2 github.com/vmware/govmomi v0.20.0 - golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 golang.org/x/mobile v0.0.0-20190607214518-6fa95d984e88 ) diff --git a/go.sum b/go.sum index 37bf74f9a..98d5f61a4 100644 --- a/go.sum +++ b/go.sum @@ -348,9 +348,8 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d h1:adrbvkTDn9rGnXg2IJDKozEpXXLZN89pdIA+Syt4/u0= golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= diff --git a/iso/builder.go b/iso/builder.go index c31267c31..ccd3e8ecb 100644 --- a/iso/builder.go +++ b/iso/builder.go @@ -105,7 +105,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &communicator.StepConnect{ Config: &b.config.Comm, Host: common.CommHost(b.config.Comm.SSHHost), - SSHConfig: common.SshConfig, + SSHConfig: b.config.Comm.SSHConfigFunc(), }, &packerCommon.StepProvision{}, &common.StepShutdown{