Closed Vonng closed 1 month ago
We are using this snippet in /pg/bin/pg-role to get the current user:
/pg/bin/pg-role
def get_user(): return os.environ["USER"]
While it may not function if a non-interactive shell is used.
We can use geteuid and getpwuid instead, which does not rely on tty or environment variable.
geteuid
getpwuid
def get_user(): try: return pwd.getpwuid(os.geteuid()).pw_name except KeyError: return ""
Thanks @ paul for bring this issue, resolve by https://github.com/Vonng/pigsty/commit/dc2dfa8a48b8107b40f6860abcb6f281fbc272f1
We are using this snippet in
/pg/bin/pg-role
to get the current user:While it may not function if a non-interactive shell is used.
We can use
geteuid
andgetpwuid
instead, which does not rely on tty or environment variable.