From 0f9eddda3ac42a0032cd13ba6e54c74823140a11 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 28 Aug 2018 17:48:09 +0200 Subject: [PATCH] builder.oracle: use c.Comm for ssh --- builder/oracle/classic/builder.go | 6 +++--- builder/oracle/common/step_ssh_key_pair.go | 15 ++++++++------- builder/oracle/oci/builder.go | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index 6f7615b8e..7ad084982 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -63,9 +63,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe // Build the steps steps := []multistep.Step{ &ocommon.StepKeyPair{ - Debug: b.config.PackerDebug, - DebugKeyPath: fmt.Sprintf("oci_classic_%s.pem", b.config.PackerBuildName), - PrivateKeyFile: b.config.Comm.SSHPrivateKeyFile, + Debug: b.config.PackerDebug, + Comm: &b.config.Comm, + DebugKeyPath: fmt.Sprintf("oci_classic_%s.pem", b.config.PackerBuildName), }, &stepCreateIPReservation{}, &stepAddKeysToAPI{}, diff --git a/builder/oracle/common/step_ssh_key_pair.go b/builder/oracle/common/step_ssh_key_pair.go index c545a09e2..cd74be7d2 100644 --- a/builder/oracle/common/step_ssh_key_pair.go +++ b/builder/oracle/common/step_ssh_key_pair.go @@ -11,22 +11,23 @@ import ( "os" "runtime" + "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" "golang.org/x/crypto/ssh" ) type StepKeyPair struct { - Debug bool - DebugKeyPath string - PrivateKeyFile string + Debug bool + Comm *communicator.Config + DebugKeyPath string } func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) - if s.PrivateKeyFile != "" { - privateKeyBytes, err := ioutil.ReadFile(s.PrivateKeyFile) + if s.Comm.SSHPrivateKeyFile != "" { + privateKeyBytes, err := ioutil.ReadFile(s.Comm.SSHPrivateKeyFile) if err != nil { err = fmt.Errorf("Error loading configured private key file: %s", err) ui.Error(err.Error()) @@ -42,8 +43,8 @@ func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep return multistep.ActionHalt } - state.Put("publicKey", string(ssh.MarshalAuthorizedKey(key.PublicKey()))) - state.Put("privateKey", string(privateKeyBytes)) + s.Comm.SSHPublicKey = ssh.MarshalAuthorizedKey(key.PublicKey()) + s.Comm.SSHPrivateKey = privateKeyBytes return multistep.ActionContinue } diff --git a/builder/oracle/oci/builder.go b/builder/oracle/oci/builder.go index 2df6ef78e..a423b1001 100644 --- a/builder/oracle/oci/builder.go +++ b/builder/oracle/oci/builder.go @@ -52,9 +52,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe // Build the steps steps := []multistep.Step{ &ocommon.StepKeyPair{ - Debug: b.config.PackerDebug, - DebugKeyPath: fmt.Sprintf("oci_%s.pem", b.config.PackerBuildName), - PrivateKeyFile: b.config.Comm.SSHPrivateKeyFile, + Debug: b.config.PackerDebug, + Comm: &b.config.Comm, + DebugKeyPath: fmt.Sprintf("oci_%s.pem", b.config.PackerBuildName), }, &stepCreateInstance{}, &stepInstanceInfo{},