20 lines
721 B
Python
20 lines
721 B
Python
|
def get_default_base_dn(server_name: str) -> str:
|
||
|
if not server_name or '.' not in server_name:
|
||
|
return None
|
||
|
values = server_name.split('.')
|
||
|
# cannot calculated base dn should be server.domain.tld
|
||
|
# remove 'server' in dn
|
||
|
if len(values) < 3:
|
||
|
return None
|
||
|
domain = ['ou=' + domain for domain in values[1:-2]]
|
||
|
domain.append(f'o={values[-2]},o={values[-1]}')
|
||
|
return ','.join(domain)
|
||
|
|
||
|
|
||
|
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=)')
|