-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use "lima" username if the local user is not a valid Linux name
At least some companies set local users via directory services and choose the email address as the user name. The '@' character is not valid in Linux usernames. Signed-off-by: Jan Dubois <jan.dubois@suse.com>
- Loading branch information
Showing
5 changed files
with
44 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package osutil | ||
|
||
import ( | ||
"fmt" | ||
"github.com/sirupsen/logrus" | ||
"os/user" | ||
"sync" | ||
|
||
"github.com/containerd/containerd/identifiers" | ||
) | ||
|
||
const ( | ||
fallbackUser = "lima" | ||
) | ||
|
||
var cache struct { | ||
sync.Once | ||
u *user.User | ||
err error | ||
warning string | ||
} | ||
|
||
func LimaUser(warn bool) (*user.User, error) { | ||
cache.Do(func() { | ||
cache.u, cache.err = user.Current() | ||
if cache.err == nil { | ||
if err := identifiers.Validate(cache.u.Username); err != nil { | ||
cache.warning = fmt.Sprintf("local user %q is not a valid Linux username: %v; using %q username instead", | ||
cache.u.Username, err, fallbackUser) | ||
} | ||
cache.u.Username = fallbackUser | ||
} | ||
}) | ||
if warn && cache.warning != "" { | ||
logrus.Warn(cache.warning) | ||
} | ||
return cache.u, cache.err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters