1
0
mirror of https://github.com/rancher/rke.git synced 2025-04-27 19:25:44 +00:00

Fall back to HOMEDRIVE+HOMEPATH or USERPROFILE

This commit is contained in:
Gert Palok 2018-05-23 12:34:57 +03:00 committed by Alena Prokharchyk
parent d909253640
commit 70fca52c33

View File

@ -114,8 +114,20 @@ func getSSHConfig(username, sshPrivateKeyString string, useAgentAuth bool) (*ssh
func privateKeyPath(sshKeyPath string) string {
if sshKeyPath[:2] == "~/" {
sshKeyPath = filepath.Join(os.Getenv("HOME"), sshKeyPath[2:])
sshKeyPath = filepath.Join(userHome(), sshKeyPath[2:])
}
buff, _ := ioutil.ReadFile(sshKeyPath)
return string(buff)
}
func userHome() string {
if home := os.Getenv("HOME"); home != "" {
return home
}
homeDrive := os.Getenv("HOMEDRIVE")
homePath := os.Getenv("HOMEPATH")
if homeDrive != "" && homePath != "" {
return homeDrive + homePath
}
return os.Getenv("USERPROFILE")
}