Skip to content
Merged
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
27 changes: 22 additions & 5 deletions githubapp/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def __init__(self):
self.LDAP_BIND_PASSWORD = os.environ["LDAP_BIND_PASSWORD"]
else:
raise Exception("LDAP credentials have not been specified")

self.USER_SYNC_ATTRIBUTE = os.environ["USER_SYNC_ATTRIBUTE"]
self.conn = Connection(
self.LDAP_SERVER_HOST,
user=self.LDAP_BIND_USER,
Expand Down Expand Up @@ -84,11 +86,26 @@ def get_group_members(self, group_name):
username = str(
member_dn["attributes"][self.LDAP_USER_ATTRIBUTE][0]
).casefold()
email = str(
member_dn["attributes"][
self.LDAP_USER_MAIL_ATTRIBUTE
][0]
).casefold()
if (
self.USER_SYNC_ATTRIBUTE == "mail"
and self.LDAP_USER_MAIL_ATTRIBUTE
not in member_dn["attributes"]
):
raise Exception(
f"{self.USER_SYNC_ATTRIBUTE} not found"
)
elif (
self.LDAP_USER_MAIL_ATTRIBUTE
in member_dn["attributes"]
):
email = str(
member_dn["attributes"][
self.LDAP_USER_MAIL_ATTRIBUTE
][0]
).casefold()
else:
email = None

user_info = {"username": username, "email": email}
member_list.append(user_info)
except Exception as e:
Expand Down