forked from stove/dataset
30 lines
1 KiB
Python
30 lines
1 KiB
Python
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=)')
|
|
|
|
|
|
def calc_ldapclient_base_dn(ldap_base_dn: str,
|
|
family_name: str=None,
|
|
base: bool=False,
|
|
group: bool=False,
|
|
) -> str:
|
|
if family_name == 'all':
|
|
family_name = None
|
|
base = True
|
|
if group:
|
|
return f'ou=groups,{ldap_base_dn}'
|
|
if not ldap_base_dn.startswith('ou=accounts,'):
|
|
base_name = f'ou=accounts,{ldap_base_dn}'
|
|
else:
|
|
base_name = ldap_base_dn
|
|
if base:
|
|
return base_name
|
|
if not family_name:
|
|
return f'ou=users,{base_name}'
|
|
base_name = f'ou=families,{base_name}'
|
|
if family_name != '-':
|
|
base_name = f'ou={family_name},{base_name}'
|
|
return base_name
|