Skip to content

Commit

Permalink
adding some debugging but ultimately everything was fine
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris McIntosh authored and Jared Murrell committed Oct 15, 2021
1 parent e873f0e commit 981c387
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
5 changes: 3 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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


Expand Down
38 changes: 23 additions & 15 deletions githubapp/ldap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import traceback
import sys
import json
import logging
from ldap3 import Server, Connection, ALL
Expand Down Expand Up @@ -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):
Expand All @@ -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)

0 comments on commit 981c387

Please sign in to comment.