proxmox: fix handling empty values in LDAP sync script

Don’t put "None" for email and such.
This commit is contained in:
Timotej Lazar 2024-08-20 15:08:57 +02:00
parent 2b4a196e4d
commit c3d1a6c4b1

View file

@ -33,7 +33,7 @@ all_users = {}
all_groups = collections.defaultdict(set) all_groups = collections.defaultdict(set)
for e in ldap.entries: for e in ldap.entries:
user = f'{e.userPrincipalName.value}@{realm}' user = f'{e.userPrincipalName.value}@{realm}'
all_users[user] = { k: e[k].value for k in e.entry_attributes } all_users[user] = { k: (e[k].value or '') for k in e.entry_attributes }
for group in e.memberOf: for group in e.memberOf:
if m := re.match(r'^CN=([^,]*)', group.replace('\\,', '-')): if m := re.match(r'^CN=([^,]*)', group.replace('\\,', '-')):
group = re.sub(r'[^A-Za-z0-9_.-]', '-', m[1]) group = re.sub(r'[^A-Za-z0-9_.-]', '-', m[1])