dataset/seed/applicationservice/2022.03.08/ldap-client/funcs/openldap_client.py

22 lines
743 B
Python
Raw Normal View History

2022-03-08 19:42:28 +01:00
def valid_base_dn(base_dn: str) -> None:
for att in ['o', 'dc', 'ou']:
if base_dn.startswith(att + '='):
break
else:
raise ValueError('La racine doit débuter par une organisation (o=), une composante du domaine (dc=) ou une unité organisationnelle (ou=)')
2022-05-04 10:29:03 +02:00
def calc_ldapclient_base_dn(ldap_base_dn: str,
family_name: str,
2022-05-07 08:11:18 +02:00
accounts: bool=False,
2022-05-04 10:29:03 +02:00
) -> str:
2022-05-07 08:11:18 +02:00
base = f'ou=accounts,{ldap_base_dn}'
if accounts:
return base
2022-05-04 10:29:03 +02:00
if not family_name:
2022-05-07 08:11:18 +02:00
return f'ou=users,{base}'
families = f'ou=families,{base}'
if family_name != '-':
return f'ou={family_name},{families}'
return families