From 86ab16931204716ff870938cc9c4a83a1a2d529d Mon Sep 17 00:00:00 2001 From: James Robinson Date: Tue, 21 May 2024 12:24:15 +0100 Subject: [PATCH] :memo: Add debug messages for each group and user added to the LDAP tree --- apricot/ldap/oauth_ldap_entry.py | 3 +++ apricot/ldap/oauth_ldap_tree.py | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apricot/ldap/oauth_ldap_entry.py b/apricot/ldap/oauth_ldap_entry.py index d945ef0..6845a33 100644 --- a/apricot/ldap/oauth_ldap_entry.py +++ b/apricot/ldap/oauth_ldap_entry.py @@ -83,3 +83,6 @@ def _bind(password: bytes) -> "OAuthLDAPEntry": raise LDAPInvalidCredentials(msg) return defer.maybeDeferred(_bind, password) + + def list_children(self) -> "list[OAuthLDAPEntry]": + return [cast(OAuthLDAPEntry, entry) for entry in self._children.values()] diff --git a/apricot/ldap/oauth_ldap_tree.py b/apricot/ldap/oauth_ldap_tree.py index 136ce31..f8bc564 100644 --- a/apricot/ldap/oauth_ldap_tree.py +++ b/apricot/ldap/oauth_ldap_tree.py @@ -67,15 +67,33 @@ def root(self) -> OAuthLDAPEntry: # Add groups to the groups OU if self.debug: - log.msg(f"Adding {len(oauth_adaptor.groups)} groups to the LDAP tree.") + log.msg( + f"Attempting to add {len(oauth_adaptor.groups)} groups to the LDAP tree." + ) for group_attrs in oauth_adaptor.groups: groups_ou.add_child(f"CN={group_attrs.cn}", group_attrs.to_dict()) + if self.debug: + children = groups_ou.list_children() + for child in children: + log.msg(f"... {child.dn.getText()}") + log.msg( + f"There are {len(children)} groups in the LDAP tree." + ) # Add users to the users OU if self.debug: - log.msg(f"Adding {len(oauth_adaptor.users)} users to the LDAP tree.") + log.msg( + f"Attempting to add {len(oauth_adaptor.users)} users to the LDAP tree." + ) for user_attrs in oauth_adaptor.users: users_ou.add_child(f"CN={user_attrs.cn}", user_attrs.to_dict()) + if self.debug: + children = users_ou.list_children() + for child in children: + log.msg(f"... {child.dn.getText()}") + log.msg( + f"There are {len(children)} users in the LDAP tree." + ) # Set last updated time log.msg("Finished building LDAP tree.")