diff --git a/.changelog/f6aec06ae77b40118322f509f6ad4096.json b/.changelog/f6aec06ae77b40118322f509f6ad4096.json new file mode 100644 index 00000000000..a9479060b4e --- /dev/null +++ b/.changelog/f6aec06ae77b40118322f509f6ad4096.json @@ -0,0 +1,8 @@ +{ + "id": "f6aec06a-e77b-4011-8322-f509f6ad4096", + "type": "feature", + "description": "Add alternative mechanism for determning the users `$HOME` or `%USERPROFILE%` location when the environment variables are not present.", + "modules": [ + "config" + ] +} \ No newline at end of file diff --git a/config/shared_config.go b/config/shared_config.go index 835d71fbc37..45f0f3ef923 100644 --- a/config/shared_config.go +++ b/config/shared_config.go @@ -8,6 +8,7 @@ import ( "io" "io/ioutil" "os" + "os/user" "path/filepath" "strings" "time" @@ -1149,8 +1150,18 @@ func (e CredentialRequiresARNError) Error() string { func userHomeDir() string { // Ignore errors since we only care about Windows and *nix. - homedir, _ := os.UserHomeDir() - return homedir + home, _ := os.UserHomeDir() + + if len(home) > 0 { + return home + } + + currUser, _ := user.Current() + if currUser != nil { + home = currUser.HomeDir + } + + return home } func oneOrNone(bs ...bool) bool {