fix: issue 2175 - fallback to env names when cannot get username from user.Current() (#2505)

mine
Łukasz Tomaszkiewicz 2024-02-15 18:17:37 +01:00 committed by GitHub
parent b55c094f93
commit 8e7b99750d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 0 deletions

View File

@ -58,6 +58,14 @@ func InNSList(nn []interface{}, ns string) bool {
func MustK9sUser() string {
usr, err := user.Current()
if err != nil {
envUsr := os.Getenv("USER")
if envUsr != "" {
return envUsr
}
envUsr = os.Getenv("LOGNAME")
if envUsr != "" {
return envUsr
}
log.Fatal().Err(err).Msg("Die on retrieving user info")
}
return usr.Username