2014-12-04 15:05:11 +01:00
|
|
|
package drivers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
2014-12-10 16:00:04 -08:00
|
|
|
"path"
|
2014-12-04 15:05:11 +01:00
|
|
|
"path/filepath"
|
2014-12-11 16:11:23 -08:00
|
|
|
|
2015-01-23 21:27:29 -05:00
|
|
|
"github.com/docker/machine/utils"
|
|
|
|
|
)
|
2015-01-02 15:20:57 -05:00
|
|
|
|
2014-12-11 16:11:23 -08:00
|
|
|
func PublicKeyPath() string {
|
2015-01-31 11:42:58 -05:00
|
|
|
return filepath.Join(utils.GetDockerDir(), "public-key.json")
|
2014-12-06 20:54:15 +01:00
|
|
|
}
|
|
|
|
|
|
2014-12-04 15:05:11 +01:00
|
|
|
func AddPublicKeyToAuthorizedHosts(d Driver, authorizedKeysPath string) error {
|
2014-12-06 20:54:15 +01:00
|
|
|
f, err := os.Open(PublicKeyPath())
|
2014-12-04 15:05:11 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
2014-12-10 16:00:04 -08:00
|
|
|
// Use path.Join here, want to create unix path even when running on Windows.
|
|
|
|
|
cmdString := fmt.Sprintf("mkdir -p %q && cat > %q", authorizedKeysPath,
|
|
|
|
|
path.Join(authorizedKeysPath, "docker-host.json"))
|
2014-12-04 15:05:11 +01:00
|
|
|
cmd, err := d.GetSSHCommand(cmdString)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
cmd.Stdin = f
|
|
|
|
|
return cmd.Run()
|
|
|
|
|
}
|
2014-12-06 20:54:15 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|