Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate using a mechanism other than whoami to determine username #1

Open
dustymabe opened this issue Mar 2, 2016 · 4 comments

Comments

@dustymabe
Copy link
Owner

We should investigate using a mechanism other than whoami to determine username. We do that here

@codylane
Copy link

@dustymabe - I'm curious if you've tried using ENV['USER'] instead of whoami for this? I'd be happy to give this a shot and see if this still works as well as put some tests behind it?

@codylane
Copy link

codylane commented Jul 6, 2020

There is also the etc ruby module that should be a much richer alternative as well. I'd suggest using the etc module route and here's an example.

[1] pry(main)> require 'etc'
=> false

[2] pry(main)> Etc.getlogin
=> "codylane"

[3] pry(main)> Etc.getpwnam(Etc.getlogin)
=> #<struct Etc::Passwd name="codylane", passwd="********", uid=501, gid=20, gecos="codylane", dir="/Users/codylane", shell="/bin/bash", change=0, uclass="", expire=0>

[4] pry(main)> Etc.getpwnam(Etc.getlogin).uid
=> 501

[5] pry(main)> Etc.getpwnam(Etc.getlogin).gid
=> 20

Here's the etc API doc for reference for 2.6.x which is the version of ruby what Vagrant 2.2.x is using

@dustymabe
Copy link
Owner Author

Seems reasonable assuming that module is in the standard library for ruby (i.e. it's not something extra that needs to be installed later).

@codylane
Copy link

codylane commented Jul 8, 2020

Agreed, for confirmation etc is part of the standard library. I'll put in a PR with some tests before the end of the week.

codylane added a commit to codylane/vagrant-sshfs that referenced this issue Jul 29, 2020
codylane added a commit to codylane/vagrant-sshfs that referenced this issue Jul 29, 2020
codylane added a commit to codylane/vagrant-sshfs that referenced this issue Aug 9, 2020
codylane added a commit to codylane/vagrant-sshfs that referenced this issue Sep 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants