mirror of
https://github.com/rancher/rke.git
synced 2025-08-07 09:54:18 +00:00
Fall back to HOMEDRIVE+HOMEPATH or USERPROFILE
This commit is contained in:
parent
d909253640
commit
70fca52c33
@ -114,8 +114,20 @@ func getSSHConfig(username, sshPrivateKeyString string, useAgentAuth bool) (*ssh
|
|||||||
|
|
||||||
func privateKeyPath(sshKeyPath string) string {
|
func privateKeyPath(sshKeyPath string) string {
|
||||||
if sshKeyPath[:2] == "~/" {
|
if sshKeyPath[:2] == "~/" {
|
||||||
sshKeyPath = filepath.Join(os.Getenv("HOME"), sshKeyPath[2:])
|
sshKeyPath = filepath.Join(userHome(), sshKeyPath[2:])
|
||||||
}
|
}
|
||||||
buff, _ := ioutil.ReadFile(sshKeyPath)
|
buff, _ := ioutil.ReadFile(sshKeyPath)
|
||||||
return string(buff)
|
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")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user