Commit b63eb462 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge branch 'ColinHebert-do_certificate'

parents 910b1610 7dc59677
...@@ -46,7 +46,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -46,7 +46,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Build the steps // Build the steps
steps := []multistep.Step{ steps := []multistep.Step{
new(stepCreateSSHKey), &stepCreateSSHKey{
Debug: b.config.PackerDebug,
DebugKeyPath: fmt.Sprintf("do_%s.pem", b.config.PackerBuildName),
},
new(stepCreateDroplet), new(stepCreateDroplet),
new(stepDropletInfo), new(stepDropletInfo),
&common.StepConnectSSH{ &common.StepConnectSSH{
......
...@@ -7,6 +7,8 @@ import ( ...@@ -7,6 +7,8 @@ import (
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"log" "log"
"os"
"runtime"
"code.google.com/p/gosshold/ssh" "code.google.com/p/gosshold/ssh"
"github.com/digitalocean/godo" "github.com/digitalocean/godo"
...@@ -16,6 +18,9 @@ import ( ...@@ -16,6 +18,9 @@ import (
) )
type stepCreateSSHKey struct { type stepCreateSSHKey struct {
Debug bool
DebugKeyPath string
keyId int keyId int
} }
...@@ -66,6 +71,31 @@ func (s *stepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction { ...@@ -66,6 +71,31 @@ func (s *stepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction {
// Remember some state for the future // Remember some state for the future
state.Put("ssh_key_id", key.ID) state.Put("ssh_key_id", key.ID)
// If we're in debug mode, output the private key to the working directory.
if s.Debug {
ui.Message(fmt.Sprintf("Saving key for debug purposes: %s", s.DebugKeyPath))
f, err := os.Create(s.DebugKeyPath)
if err != nil {
state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
return multistep.ActionHalt
}
defer f.Close()
// Write the key out
if _, err := f.Write(pem.EncodeToMemory(&priv_blk)); err != nil {
state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
return multistep.ActionHalt
}
// Chmod it so that it is SSH ready
if runtime.GOOS != "windows" {
if err := f.Chmod(0600); err != nil {
state.Put("error", fmt.Errorf("Error setting permissions of debug key: %s", err))
return multistep.ActionHalt
}
}
}
return multistep.ActionContinue return multistep.ActionContinue
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment