2021-02-23 22:32:52 +01:00
|
|
|
from .management.commands._ldap import ClipperLDAP
|
2021-02-06 12:34:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_ldap_infos(clipper_login):
|
2021-02-23 22:32:52 +01:00
|
|
|
ldap = ClipperLDAP()
|
2021-02-06 17:04:24 +01:00
|
|
|
try:
|
2021-02-23 22:32:52 +01:00
|
|
|
res = ldap.search("(uid={})".format(clipper_login))
|
|
|
|
except Exception:
|
2021-02-06 17:04:24 +01:00
|
|
|
return None
|
2021-02-06 12:34:02 +01:00
|
|
|
|
|
|
|
if not res:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if len(res) != 1:
|
|
|
|
raise RuntimeError("LDAP returned too many results: {}".format(res))
|
|
|
|
(res,) = res
|
2021-02-23 22:32:52 +01:00
|
|
|
promo, dept = ldap.parse_dept(ldap.extract_ldap_info(res, "homeDirectory"))
|
2021-02-06 12:34:02 +01:00
|
|
|
|
2021-02-23 22:32:52 +01:00
|
|
|
return {
|
|
|
|
"name": ldap.extract_ldap_info(res, "cn"),
|
|
|
|
"promo": promo,
|
|
|
|
"dept": dept,
|
|
|
|
}
|