GetComponents assumes that $USER is defined
Currently GetComponents assumes that the $USER
environment variable is set. This is not true inside of docker containers and requires some workarounds in the Dockerfile to handle correctly.
Pull request https://github.com/gridaphobe/CRL/pull/11/files instead uses Perl’s getpwuid
to get the user name from the OS which does not rely on USER. I tested getpwuid to work fine in a Ubuntu container.
Comments (7)
-
reporter -
I believe that simfactory also assumes this.
-
reporter ugh, I did not know that. Checking… Simfactory has “workarounds”:
def GetUsername(): if "USER" not in os.environ: fd = simenv.popen("whoami") username = fd.read().strip() fd.close() else: username = os.environ["USER"] return username
What’s wrong with
os.getlogin()
which is the first answer that Google finds for “Python get user name”: https://www.geeksforgeeks.org/how-to-get-the-current-username-in-python/ and apparently part of Python since forever?
I’ll make a pull request for simfactory as well. -
reporter Here is one for simfactory: https://bitbucket.org/simfactory/simfactory2/pull-requests/63/use-osgetlogin-instead-of-user
-
reporter @Steven R. Brandt says “please apply”
-
reporter Applied as git hash 709ffeb "GetComponents: use getpwuid instead of USER" of CRL
Applied as git hash 83fccb88 "test-sim: use os.getlogin() instead of $USER" of simfactory2
-
reporter - changed status to resolved
- Log in to comment
Please review.