Check that public key exists when creating machine
Fixes #4 Signed-off-by: Ben Firshman <ben@firshman.co.uk>
This commit is contained in:
@@ -180,6 +180,14 @@ func (cli *DockerCli) CmdCreate(args ...string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
keyExists, err := drivers.PublicKeyExists()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !keyExists {
|
||||
log.Fatalf("Identity auth public key does not exist at %s. Please run the docker client without any options to create it.", drivers.PublicKeyPath())
|
||||
}
|
||||
|
||||
name := cmd.Arg(0)
|
||||
|
||||
store := NewStore()
|
||||
|
||||
@@ -6,8 +6,12 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func PublicKeyPath() string {
|
||||
return filepath.Join(os.Getenv("HOME"), ".docker/public-key.json")
|
||||
}
|
||||
|
||||
func AddPublicKeyToAuthorizedHosts(d Driver, authorizedKeysPath string) error {
|
||||
f, err := os.Open(filepath.Join(os.Getenv("HOME"), ".docker/public-key.json"))
|
||||
f, err := os.Open(PublicKeyPath())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -21,3 +25,13 @@ func AddPublicKeyToAuthorizedHosts(d Driver, authorizedKeysPath string) error {
|
||||
cmd.Stdin = f
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func PublicKeyExists() (bool, error) {
|
||||
_, err := os.Stat(PublicKeyPath())
|
||||
if err == nil {
|
||||
return true, nil
|
||||
} else if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user