Merge pull request #33 from bfirsh/check-that-public-key-exists-when-creating-machines

Check that public key exists when creating machine
This commit is contained in:
Ben Firshman 2014-12-08 20:42:00 +00:00
commit cd31776e0b
2 changed files with 23 additions and 1 deletions

View File

@ -180,6 +180,14 @@ func (cli *DockerCli) CmdCreate(args ...string) error {
return nil 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) name := cmd.Arg(0)
store := NewStore() store := NewStore()

View File

@ -6,8 +6,12 @@ import (
"path/filepath" "path/filepath"
) )
func PublicKeyPath() string {
return filepath.Join(os.Getenv("HOME"), ".docker/public-key.json")
}
func AddPublicKeyToAuthorizedHosts(d Driver, authorizedKeysPath string) error { 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 { if err != nil {
return err return err
} }
@ -21,3 +25,13 @@ func AddPublicKeyToAuthorizedHosts(d Driver, authorizedKeysPath string) error {
cmd.Stdin = f cmd.Stdin = f
return cmd.Run() 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
}