Skip to content

Commit

Permalink
Fixing logic around mail attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris McIntosh authored and Jared Murrell committed Jan 5, 2022
1 parent cd035ed commit 728da02
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 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,16 +86,26 @@ def get_group_members(self, group_name):
username = str(
member_dn["attributes"][self.LDAP_USER_ATTRIBUTE][0]
).casefold()
if member_dn["attributes"][
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

0 comments on commit 728da02

Please sign in to comment.