Check that public key exists when creating machine

Fixes #4

Signed-off-by: Ben Firshman <ben@firshman.co.uk>
This commit is contained in:
Ben Firshman
2014-12-06 20:54:15 +01:00
parent 2e9fe4df45
commit dcf081d758
2 changed files with 23 additions and 1 deletions

View File

@@ -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()

View File

@@ -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
}