Use native go method to get current user rather than environment variable#4930
Merged
Conversation
adelowo
approved these changes
Sep 13, 2018
Member
|
Blocked until 1.6.0-rc1 is released |
sapk
suggested changes
Sep 18, 2018
Member
sapk
left a comment
There was a problem hiding this comment.
Looks good just need a little change.
lafriks
approved these changes
Sep 18, 2018
sapk
approved these changes
Sep 18, 2018
Codecov Report
@@ Coverage Diff @@
## master #4930 +/- ##
=========================================
+ Coverage 37.4% 37.4% +<.01%
=========================================
Files 306 306
Lines 45378 45389 +11
=========================================
+ Hits 16974 16980 +6
- Misses 25949 25954 +5
Partials 2455 2455
Continue to review full report at Codecov.
|
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
whoamicommand 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.