Use native go method to get current user rather than environment variable #4930
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1640, #4894
Native "os/user" go package has good function to retrieve current user, rather than relying on USER environment variable.
If getting current user doesn't work on target OS (for example, not yet implemented for it) - it falls back to old implementation with environment variables.
Unit test also changed, old one won't work because USER environment variable spoofing doesn't work anymore (unless os/user is not implemented for OS under which tests are run), now it just compares CurrentUser() with
whoami
command output (skipped on Windows where whoami behaves different way).For Windows OS with "domain\username" format, only second part (username) is returned to match previous behavior and trim unnecessary prefix.