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
76a82216
Commit
76a82216
authored
Sep 03, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/*: extract key path to ssh.Signer
parent
414bf174
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
61 additions
and
103 deletions
+61
-103
builder/parallels/common/ssh.go
builder/parallels/common/ssh.go
+4
-24
builder/parallels/common/ssh_config.go
builder/parallels/common/ssh_config.go
+4
-2
builder/qemu/builder.go
builder/qemu/builder.go
+6
-4
builder/qemu/ssh.go
builder/qemu/ssh.go
+4
-24
builder/virtualbox/common/ssh.go
builder/virtualbox/common/ssh.go
+4
-24
builder/virtualbox/common/ssh_config.go
builder/virtualbox/common/ssh_config.go
+4
-2
builder/vmware/common/ssh.go
builder/vmware/common/ssh.go
+3
-22
builder/vmware/common/ssh_config.go
builder/vmware/common/ssh_config.go
+2
-1
common/ssh/key.go
common/ssh/key.go
+30
-0
No files found.
builder/parallels/common/ssh.go
View file @
76a82216
package
common
import
(
"code.google.com/p/go.crypto/ssh"
"fmt"
"code.google.com/p/go.crypto/ssh"
"github.com/mitchellh/multistep"
commonssh
"github.com/mitchellh/packer/common/ssh"
packerssh
"github.com/mitchellh/packer/communicator/ssh"
"io/ioutil"
"os"
)
func
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
...
...
@@ -35,7 +35,7 @@ func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*ssh.ClientConfig
}
if
config
.
SSHKeyPath
!=
""
{
signer
,
err
:=
sshKeyTo
Signer
(
config
.
SSHKeyPath
)
signer
,
err
:=
commonssh
.
File
Signer
(
config
.
SSHKeyPath
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -49,23 +49,3 @@ func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*ssh.ClientConfig
},
nil
}
}
func
sshKeyToSigner
(
path
string
)
(
ssh
.
Signer
,
error
)
{
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
defer
f
.
Close
()
keyBytes
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
return
nil
,
err
}
signer
,
err
:=
ssh
.
ParsePrivateKey
(
keyBytes
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error setting up SSH config: %s"
,
err
)
}
return
signer
,
nil
}
builder/parallels/common/ssh_config.go
View file @
76a82216
...
...
@@ -3,9 +3,11 @@ package common
import
(
"errors"
"fmt"
"github.com/mitchellh/packer/packer"
"os"
"time"
commonssh
"github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/packer"
)
type
SSHConfig
struct
{
...
...
@@ -46,7 +48,7 @@ func (c *SSHConfig) Prepare(t *packer.ConfigTemplate) []error {
if
c
.
SSHKeyPath
!=
""
{
if
_
,
err
:=
os
.
Stat
(
c
.
SSHKeyPath
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
else
if
_
,
err
:=
sshKeyTo
Signer
(
c
.
SSHKeyPath
);
err
!=
nil
{
}
else
if
_
,
err
:=
commonssh
.
File
Signer
(
c
.
SSHKeyPath
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
}
...
...
builder/qemu/builder.go
View file @
76a82216
...
...
@@ -3,15 +3,17 @@ package qemu
import
(
"errors"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
commonssh
"github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/packer"
)
const
BuilderId
=
"transcend.qemu"
...
...
@@ -352,7 +354,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
if
_
,
err
:=
os
.
Stat
(
b
.
config
.
SSHKeyPath
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
else
if
_
,
err
:=
sshKeyTo
Signer
(
b
.
config
.
SSHKeyPath
);
err
!=
nil
{
}
else
if
_
,
err
:=
commonssh
.
File
Signer
(
b
.
config
.
SSHKeyPath
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
...
...
builder/qemu/ssh.go
View file @
76a82216
package
qemu
import
(
gossh
"code.google.com/p/go.crypto/ssh"
"fmt"
gossh
"code.google.com/p/go.crypto/ssh"
"github.com/mitchellh/multistep"
commonssh
"github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/communicator/ssh"
"io/ioutil"
"os"
)
func
sshAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
...
...
@@ -24,7 +24,7 @@ func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) {
}
if
config
.
SSHKeyPath
!=
""
{
signer
,
err
:=
sshKeyTo
Signer
(
config
.
SSHKeyPath
)
signer
,
err
:=
commonssh
.
File
Signer
(
config
.
SSHKeyPath
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -37,23 +37,3 @@ func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) {
Auth
:
auth
,
},
nil
}
func
sshKeyToSigner
(
path
string
)
(
gossh
.
Signer
,
error
)
{
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
defer
f
.
Close
()
keyBytes
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
return
nil
,
err
}
signer
,
err
:=
gossh
.
ParsePrivateKey
(
keyBytes
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error setting up SSH config: %s"
,
err
)
}
return
signer
,
nil
}
builder/virtualbox/common/ssh.go
View file @
76a82216
package
common
import
(
gossh
"code.google.com/p/go.crypto/ssh"
"fmt"
gossh
"code.google.com/p/go.crypto/ssh"
"github.com/mitchellh/multistep"
commonssh
"github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/communicator/ssh"
"io/ioutil"
"os"
)
func
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
...
...
@@ -23,7 +23,7 @@ func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*gossh.ClientConf
}
if
config
.
SSHKeyPath
!=
""
{
signer
,
err
:=
sshKeyTo
Signer
(
config
.
SSHKeyPath
)
signer
,
err
:=
commonssh
.
File
Signer
(
config
.
SSHKeyPath
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -37,23 +37,3 @@ func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*gossh.ClientConf
},
nil
}
}
func
sshKeyToSigner
(
path
string
)
(
gossh
.
Signer
,
error
)
{
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
defer
f
.
Close
()
keyBytes
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
return
nil
,
err
}
signer
,
err
:=
gossh
.
ParsePrivateKey
(
keyBytes
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error setting up SSH config: %s"
,
err
)
}
return
signer
,
nil
}
builder/virtualbox/common/ssh_config.go
View file @
76a82216
...
...
@@ -3,9 +3,11 @@ package common
import
(
"errors"
"fmt"
"github.com/mitchellh/packer/packer"
"os"
"time"
commonssh
"github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/packer"
)
type
SSHConfig
struct
{
...
...
@@ -56,7 +58,7 @@ func (c *SSHConfig) Prepare(t *packer.ConfigTemplate) []error {
if
c
.
SSHKeyPath
!=
""
{
if
_
,
err
:=
os
.
Stat
(
c
.
SSHKeyPath
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
else
if
_
,
err
:=
sshKeyTo
Signer
(
c
.
SSHKeyPath
);
err
!=
nil
{
}
else
if
_
,
err
:=
commonssh
.
File
Signer
(
c
.
SSHKeyPath
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
}
...
...
builder/vmware/common/ssh.go
View file @
76a82216
package
common
import
(
gossh
"code.google.com/p/go.crypto/ssh"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
gossh
"code.google.com/p/go.crypto/ssh"
"github.com/mitchellh/multistep"
commonssh
"github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/communicator/ssh"
)
...
...
@@ -74,7 +75,7 @@ func SSHConfigFunc(config *SSHConfig) func(multistep.StateBag) (*gossh.ClientCon
}
if
config
.
SSHKeyPath
!=
""
{
signer
,
err
:=
sshKeyTo
Signer
(
config
.
SSHKeyPath
)
signer
,
err
:=
commonssh
.
File
Signer
(
config
.
SSHKeyPath
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -88,23 +89,3 @@ func SSHConfigFunc(config *SSHConfig) func(multistep.StateBag) (*gossh.ClientCon
},
nil
}
}
func
sshKeyToSigner
(
path
string
)
(
gossh
.
Signer
,
error
)
{
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
defer
f
.
Close
()
keyBytes
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
return
nil
,
err
}
signer
,
err
:=
gossh
.
ParsePrivateKey
(
keyBytes
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error setting up SSH config: %s"
,
err
)
}
return
signer
,
nil
}
builder/vmware/common/ssh_config.go
View file @
76a82216
...
...
@@ -7,6 +7,7 @@ import (
"os"
"time"
commonssh
"github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/packer"
)
...
...
@@ -51,7 +52,7 @@ func (c *SSHConfig) Prepare(t *packer.ConfigTemplate) []error {
if
c
.
SSHKeyPath
!=
""
{
if
_
,
err
:=
os
.
Stat
(
c
.
SSHKeyPath
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
else
if
_
,
err
:=
sshKeyTo
Signer
(
c
.
SSHKeyPath
);
err
!=
nil
{
}
else
if
_
,
err
:=
commonssh
.
File
Signer
(
c
.
SSHKeyPath
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"ssh_key_path is invalid: %s"
,
err
))
}
}
...
...
common/ssh/key.go
0 → 100644
View file @
76a82216
package
ssh
import
(
"fmt"
"io/ioutil"
"os"
"code.google.com/p/go.crypto/ssh"
)
// FileSigner returns an ssh.Signer for a key file.
func
FileSigner
(
path
string
)
(
ssh
.
Signer
,
error
)
{
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
defer
f
.
Close
()
keyBytes
,
err
:=
ioutil
.
ReadAll
(
f
)
if
err
!=
nil
{
return
nil
,
err
}
signer
,
err
:=
ssh
.
ParsePrivateKey
(
keyBytes
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error setting up SSH config: %s"
,
err
)
}
return
signer
,
nil
}
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