diff --git a/githubapp/ldap.py b/githubapp/ldap.py index 4daabc3..be8f4bd 100644 --- a/githubapp/ldap.py +++ b/githubapp/ldap.py @@ -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, @@ -84,9 +86,18 @@ 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 @@ -94,6 +105,7 @@ def get_group_members(self, group_name): ).casefold() else: email = None + user_info = {"username": username, "email": email} member_list.append(user_info) except Exception as e: