Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase debug verbosity for users and groups #40

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apricot/ldap/oauth_ldap_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
18 changes: 16 additions & 2 deletions apricot/ldap/oauth_ldap_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,29 @@ 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.")
Expand Down
10 changes: 10 additions & 0 deletions apricot/oauth/oauth_data_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ def _retrieve_entries(
for parent_dict in oauth_groups + user_primary_groups + groups_of_groups
if child_dn in parent_dict["member"]
]
if self.debug:
for group_name in child_dict["memberOf"]:
log.msg(
f"... user '{child_dict['cn']}' is a member of '{group_name}'"
)

# Ensure memberOf is set correctly for groups
for child_dict in oauth_groups + user_primary_groups + groups_of_groups:
Expand All @@ -137,6 +142,11 @@ def _retrieve_entries(
for parent_dict in oauth_groups + user_primary_groups + groups_of_groups
if child_dn in parent_dict["member"]
]
if self.debug:
for group_name in child_dict["memberOf"]:
log.msg(
f"... group '{child_dict['cn']}' is a member of '{group_name}'"
)

# Annotate group and user dicts with the appropriate LDAP classes
annotated_groups = [
Expand Down
Loading