forked from rancher/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
42 lines (36 loc) · 867 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package drivers
import (
"fmt"
"os"
"path"
"path/filepath"
"github.com/docker/machine/utils"
)
func PublicKeyPath() string {
return filepath.Join(utils.GetDockerDir(), "public-key.json")
}
func AddPublicKeyToAuthorizedHosts(d Driver, authorizedKeysPath string) error {
f, err := os.Open(PublicKeyPath())
if err != nil {
return err
}
defer f.Close()
// 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"))
cmd, err := d.GetSSHCommand(cmdString)
if err != nil {
return err
}
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
}