From 981c387c8e44fd3be4676f17e882466ddf11dace Mon Sep 17 00:00:00 2001 From: Chris McIntosh Date: Fri, 15 Oct 2021 13:55:13 -0500 Subject: [PATCH] adding some debugging but ultimately everything was fine --- app.py | 5 +++-- githubapp/ldap.py | 38 +++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/app.py b/app.py index 7786e44..951aaae 100644 --- a/app.py +++ b/app.py @@ -70,7 +70,8 @@ def sync_team(client=None, owner=None, team_id=None, slug=None): directory_members = directory_group_members(group=directory_group) except Exception as e: directory_members = [] - print(e) + traceback.print_exc(file=sys.stderr) + team_members = github_team_members( client=client, owner=owner, team_id=team_id, attribute=USER_SYNC_ATTRIBUTE ) @@ -108,7 +109,7 @@ def directory_group_members(group=None): group_members = [member for member in members] except Exception as e: group_members = [] - print(e) + traceback.print_exc(file=sys.stderr) return group_members diff --git a/githubapp/ldap.py b/githubapp/ldap.py index e9ab04e..121e423 100644 --- a/githubapp/ldap.py +++ b/githubapp/ldap.py @@ -1,4 +1,6 @@ import os +import traceback +import sys import json import logging from ldap3 import Server, Connection, ALL @@ -73,18 +75,23 @@ def get_group_members(self, group_name): try: member_dn = self.get_user_info(user=member) # pprint(member_dn) - username = str( - member_dn["attributes"][self.LDAP_USER_ATTRIBUTE][0] - ).casefold() - email = str( - member_dn["attributes"][self.LDAP_USER_MAIL_ATTRIBUTE][ - 0 - ] - ).casefold() - user_info = {"username": username, "email": email} - member_list.append(user_info) + if ( + member_dn + and member_dn["attributes"] + and member_dn["attributes"][self.LDAP_USER_ATTRIBUTE] + ): + username = str( + member_dn["attributes"][self.LDAP_USER_ATTRIBUTE][0] + ).casefold() + email = str( + member_dn["attributes"][ + self.LDAP_USER_MAIL_ATTRIBUTE + ][0] + ).casefold() + user_info = {"username": username, "email": email} + member_list.append(user_info) except Exception as e: - print(e) + traceback.print_exc(file=sys.stderr) return member_list def get_user_info(self, user=None): @@ -106,9 +113,10 @@ def get_user_info(self, user=None): search_filter=self.LDAP_USER_FILTER.replace("{username}", user), attributes=["*"], ) - data = json.loads(self.conn.entries[0].entry_to_json()) - return data + if len(self.conn.entries) > 0: + data = json.loads(self.conn.entries[0].entry_to_json()) + return data except Exception as e: - print(e) + traceback.print_exc(file=sys.stderr) except Exception as e: - print(e) + traceback.print_exc(file=sys.stderr)