Python CSC Electronic Office
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pyceo/ceo/krb_check.py

36 lines
819 B

2 years ago
import subprocess
import gssapi
_username = None
def get_username():
"""Get the user currently logged into CEO."""
return _username
2 years ago
def krb_check():
"""
Spawns a `kinit` process if no credentials are available or the
credentials have expired.
Stores the username for later use by get_username().
2 years ago
"""
global _username
for _ in range(2):
try:
creds = gssapi.Credentials(usage='initiate')
result = creds.inquire()
princ = str(result.name)
_username = princ[:princ.index('@')]
return
except (gssapi.raw.misc.GSSError, gssapi.raw.exceptions.ExpiredCredentialsError):
kinit()
2 years ago
raise Exception('could not acquire GSSAPI credentials')
2 years ago
def kinit():
subprocess.run(['kinit'], check=True)