builder.oracle: use c.Comm for ssh

This commit is contained in:
Adrien Delorme 2018-08-28 17:48:09 +02:00
parent 92570a2725
commit 0f9eddda3a
3 changed files with 14 additions and 13 deletions

View File

@ -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{},

View File

@ -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
}

View File

@ -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{},