mirror of https://github.com/docker/docs.git
24 lines
506 B
Go
24 lines
506 B
Go
package drivers
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func AddPublicKeyToAuthorizedHosts(d Driver, authorizedKeysPath string) error {
|
|
f, err := os.Open(filepath.Join(os.Getenv("HOME"), ".docker/public-key.json"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
|
|
cmdString := fmt.Sprintf("mkdir -p %q && cat > %q", authorizedKeysPath, filepath.Join(authorizedKeysPath, "docker-host.json"))
|
|
cmd, err := d.GetSSHCommand(cmdString)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cmd.Stdin = f
|
|
return cmd.Run()
|
|
}
|