Skip to content

Commit

Permalink
fix ldap_sync encoding bug
Browse files Browse the repository at this point in the history
  • Loading branch information
diegocepedaw authored and jwon committed Mar 10, 2021
1 parent 416991f commit aa14690
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'streql',
'webassets',
'beaker',
'cryptography',
'cryptography==2.3',
'python-ldap',
'pytz',
'irisclient',
Expand Down
16 changes: 12 additions & 4 deletions src/oncall/user_sync/ldap_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@


def normalize_phone_number(num):
return format_number(parse(num.decode('utf-8'), 'US'), PhoneNumberFormat.INTERNATIONAL)
return format_number(parse(num, 'US'), PhoneNumberFormat.INTERNATIONAL)


def get_predefined_users(config):
Expand Down Expand Up @@ -131,21 +131,29 @@ def fetch_ldap():
username_field = "sAMAccountName"

username = ldap_dict[username_field][0]

if isinstance(username, bytes):
username = username.decode("utf-8")
name = ldap_dict.get(LDAP_SETTINGS['attrs']['full_name'])[0]
if isinstance(name, bytes):
name = name.decode("utf-8")
mobile = ldap_dict.get(LDAP_SETTINGS['attrs']['mobile'])
mail = ldap_dict.get(LDAP_SETTINGS['attrs']['mail'])
name = ldap_dict.get(LDAP_SETTINGS['attrs']['full_name'])[0]

if mobile:
try:
mobile = normalize_phone_number(mobile[0])
mobile = mobile[0]
if isinstance(mobile, bytes):
mobile = mobile.decode("utf-8")
mobile = normalize_phone_number(mobile)
except NumberParseException:
mobile = None
except UnicodeEncodeError:
mobile = None

if mail:
mail = mail[0]
if isinstance(mail, bytes):
mail = mail.decode("utf-8")
slack = mail.split('@')[0]
else:
slack = None
Expand Down

0 comments on commit aa14690

Please sign in to comment.