Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
42d05368
Commit
42d05368
authored
Jan 10, 2015
by
Colin Hebert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save the generated SSH key as a file in debug mode
parent
4a0c242c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
builder/digitalocean/builder.go
builder/digitalocean/builder.go
+4
-1
builder/digitalocean/step_create_ssh_key.go
builder/digitalocean/step_create_ssh_key.go
+30
-1
No files found.
builder/digitalocean/builder.go
View file @
42d05368
...
...
@@ -244,7 +244,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Build the steps
steps
:=
[]
multistep
.
Step
{
new
(
stepCreateSSHKey
),
&
stepCreateSSHKey
{
Debug
:
b
.
config
.
PackerDebug
,
DebugKeyPath
:
fmt
.
Sprintf
(
"do_%s.pem"
,
b
.
config
.
PackerBuildName
),
},
new
(
stepCreateDroplet
),
new
(
stepDropletInfo
),
&
common
.
StepConnectSSH
{
...
...
builder/digitalocean/step_create_ssh_key.go
View file @
42d05368
...
...
@@ -7,6 +7,8 @@ import (
"encoding/pem"
"fmt"
"log"
"runtime"
"os"
"code.google.com/p/gosshold/ssh"
"github.com/mitchellh/multistep"
...
...
@@ -15,7 +17,9 @@ import (
)
type
stepCreateSSHKey
struct
{
keyId
uint
Debug
bool
DebugKeyPath
string
keyId
uint
}
func
(
s
*
stepCreateSSHKey
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
...
...
@@ -62,6 +66,31 @@ func (s *stepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction {
// Remember some state for the future
state
.
Put
(
"ssh_key_id"
,
keyId
)
// 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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment