in community/front-end/ofe/infrastructure_files/gcs_bucket/clusters/ansible_setup/roles/c2_daemon/files/ghpcfe_c2daemon.py [0:0]
def _verify_oslogin_user(login_uid):
# (username, uid, gid, homedir) = \
# _verify_oslogin_user(message['login_uid']):
# Raises KeyError if login_uid not found in list
global _OSLOGIN_CACHE
if login_uid not in _OSLOGIN_CACHE:
# pylint: disable=line-too-long
# TODO - wrap in a loop with page Tokens
req = requests.get(
GCS_METADATA_BASEURL + "oslogin/users?pagesize=1024",
headers=GCS_METADATA_HEADERS
)
resp = json.loads(req.text)
_OSLOGIN_CACHE = {}
for profile in resp["loginProfiles"]:
uid = profile["name"]
# TODO: Should also check login authorization
for acct in profile["posixAccounts"]:
if acct["primary"] or len(profile["posixAccounts"]) == 1:
_OSLOGIN_CACHE[uid] = (
acct["username"],
int(acct["uid"]),
int(acct["gid"]),
acct["homeDirectory"],
)
# Check to see if Homedir exists, and create if not
homedir_path = Path(acct["homeDirectory"])
if not homedir_path.is_dir():
logger.info(
"Creating homedir for user %s at %s",
acct["username"],
acct["homeDirectory"],
)
try:
subprocess.run(
["mkhomedir_helper", acct["username"]],
check=True,
)
except Exception as err:
logger.error("Error creating homedir", exc_info=err)
return _OSLOGIN_CACHE[login_uid]