Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ liam = instance.get_member_slackuid(slack_uid)
# Get group by cn
rtp = instance.get_group('rtp')

# get group member uids
rtp = instance.get_group('rtp').get_members(uids=True)

# Get cn of member
print(liam.cn)

Expand Down
20 changes: 12 additions & 8 deletions csh_ldap/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, lib, search_val):
raise KeyError("Invalid Search Name")

@reconnect_on_fail
def get_members(self):
def get_members(self, uids=False):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just make a def get_member_uids(self)? uids=False implies that uids=True will return what uids=False does but also with UIDs, not return less. At least clarify the parameter (uids_only?) and add documentation as to what it returns.

"""Return all members in the group as CSHMember objects"""
res = self.__con__.search_s(
self.__ldap_base_dn__,
Expand All @@ -40,13 +40,17 @@ def get_members(self):

ret = []
for val in res:
val = val[1]['uid'][0]
try:
ret.append(val.decode('utf-8'))
except UnicodeDecodeError:
ret.append(val)
except KeyError:
continue
if 'uid' in val[1]:

@cecilialau6776 cecilialau6776 Jun 11, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flatten this block:

if 'uid' not in val[1]:
    continue
val = ...

val = val[1]['uid'][0]
try:
ret.append(val.decode('utf-8'))
except UnicodeDecodeError:
ret.append(val)
except KeyError:
continue

if uids:
return ret

return [CSHMember(self.__lib__,
result,
Expand Down
Loading