#311 Use getpass.getuser() instead of pwd.getpwuid(os.getuid())[0]
Merged by cqi. Opened by jpopelka.
jpopelka/rpkg getpass  into  master

Download 311.patch

getpass.getuser() eventually also calls pwd.getpwuid(os.getuid())[0],
but first checks whether there's any of LOGNAME, USER, LNAME and USERNAME
env. variables set. If yes, then it returns its value.

This is useful in Openshift where a container has random uid
and getpwuid(random_uid) fails with:
KeyError: 'getpwuid(): uid not found: random_uid'

Signed-off-by: Jiri Popelka jpopelka@redhat.com

Looks good to me.

I'm trying this locally and still getting an exception:

$ docker run -ti -u 1005 registry.fedoraproject.org/fedora:28 bash
bash-4.4$ python3
Python 3.6.5 (default, Mar 29 2018, 18:20:46)
[GCC 8.0.1 20180317 (Red Hat 8.0.1-0.19)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import getpass
>>> getpass.getuser()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.6/getpass.py", line 169, in getuser
    return pwd.getpwuid(os.getuid())[0]
KeyError: 'getpwuid(): uid not found: 1005'
>>> 

That's the fallback which is still going to fail. However you can define one of the env vars which will be used first.

Ah, now I get it. LGTM then!

pretty please pagure-ci rebuild

rebased onto 858bdfbdf1071fefc9813b8a466db0441ce4ac51

Looks good to me. Thanks.

Commit 46130d45 fixes this pull-request

Pull-Request has been merged by cqi

Pull-Request has been merged by cqi

Metadata