fall back to env var USER when /etc/passwd and stdlib faculties fail to resolve the UID

This commit is contained in:
Kenneth Bingham 2024-03-13 23:11:45 -04:00
parent d3147d6ed9
commit 98e7983bf5
No known key found for this signature in database
GPG Key ID: 31709281860130B6
2 changed files with 11 additions and 3 deletions

View File

@ -4,6 +4,8 @@
FIX: Also update the Python SDK to include the permission mode and access grants fields on the `ShareRequest` (https://github.com/openziti/zrok/issues/432)
FIX: Add a way to find the username on Linux when /etc/passwd and stdlib can't resolve the UID (https://github.com/openziti/zrok/issues/454)
## v0.4.26
FEATURE: New _permission modes_ available for shares. _Open permission mode_ retains the behavior of previous zrok releases and is the default setting. _Closed permission mode_ (`--closed`) only allows a share to be accessed (`zrok access`) by users who have been granted access with the `--access-grant` flag. See the documentation at (https://docs.zrok.io/docs/guides/permission-modes/) (https://github.com/openziti/zrok/issues/432)

View File

@ -56,13 +56,19 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
if err != nil {
panic(err)
}
var username string
user, err := user2.Current()
if err != nil {
panic(err)
username := os.Getenv("USER")
if username == "" {
logrus.Panicf("unable to determine the current user: %v", err)
}
} else {
username = user.Username
}
hostDetail = fmt.Sprintf("%v; %v", user.Username, hostDetail)
hostDetail = fmt.Sprintf("%v; %v", username, hostDetail)
if cmd.description == "<user>@<hostname>" {
cmd.description = fmt.Sprintf("%v@%v", user.Username, hostName)
cmd.description = fmt.Sprintf("%v@%v", username, hostName)
}
zrok, err := env.Client()
if err != nil {