From 585b93cfd6dc13c25855d487c188e40acd37c3d8 Mon Sep 17 00:00:00 2001 From: DanHam Date: Thu, 3 May 2018 00:17:51 +0100 Subject: [PATCH 1/2] Follow variable privateKey <-> statebag private_key convention --- builder/scaleway/ssh.go | 2 +- builder/scaleway/step_create_ssh_key.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builder/scaleway/ssh.go b/builder/scaleway/ssh.go index a2c9b8f16..946c2046f 100644 --- a/builder/scaleway/ssh.go +++ b/builder/scaleway/ssh.go @@ -46,7 +46,7 @@ func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { } if config.Comm.SSHPrivateKey != "" { - if priv, ok := state.GetOk("privateKey"); ok { + if priv, ok := state.GetOk("private_key"); ok { privateKey = priv.(string) } signer, err := ssh.ParsePrivateKey([]byte(privateKey)) diff --git a/builder/scaleway/step_create_ssh_key.go b/builder/scaleway/step_create_ssh_key.go index c5405ccd6..4272d9ff4 100644 --- a/builder/scaleway/step_create_ssh_key.go +++ b/builder/scaleway/step_create_ssh_key.go @@ -36,7 +36,7 @@ func (s *stepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult return multistep.ActionHalt } - state.Put("privateKey", string(privateKeyBytes)) + state.Put("private_key", string(privateKeyBytes)) state.Put("ssh_pubkey", "") return multistep.ActionContinue @@ -61,7 +61,7 @@ func (s *stepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult } // Set the private key in the statebag for later - state.Put("privateKey", string(pem.EncodeToMemory(&priv_blk))) + state.Put("private_key", string(pem.EncodeToMemory(&priv_blk))) pub, _ := ssh.NewPublicKey(&priv.PublicKey) pub_sshformat := string(ssh.MarshalAuthorizedKey(pub)) From c47e5d19f036fdb6f5a79de29961fbdb043972b3 Mon Sep 17 00:00:00 2001 From: DanHam Date: Thu, 3 May 2018 11:33:28 +0100 Subject: [PATCH 2/2] Fix use of auto generated ssh key for scaleway builder --- builder/scaleway/ssh.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/builder/scaleway/ssh.go b/builder/scaleway/ssh.go index 946c2046f..e4677849f 100644 --- a/builder/scaleway/ssh.go +++ b/builder/scaleway/ssh.go @@ -18,7 +18,6 @@ func commHost(state multistep.StateBag) (string, error) { func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { config := state.Get("config").(Config) - var privateKey string var auth []ssh.AuthMethod @@ -45,11 +44,9 @@ func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { ) } - if config.Comm.SSHPrivateKey != "" { - if priv, ok := state.GetOk("private_key"); ok { - privateKey = priv.(string) - } - signer, err := ssh.ParsePrivateKey([]byte(privateKey)) + // Use key based auth if there is a private key in the state bag + if privateKey, ok := state.GetOk("private_key"); ok { + signer, err := ssh.ParsePrivateKey([]byte(privateKey.(string))) if err != nil { return nil, fmt.Errorf("Error setting up SSH config: %s", err) }