GetComponents assumes that $USER is defined

Create issue
Issue #2612 resolved
Roland Haas created an issue

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)

  1. Roland Haas 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.

  2. Log in to comment