Connect to IBM's LDAP, Bluepages, with Python
Steve Martinelli
by Steve Martinelli

Tags

  • software
  • ibm
  • python
  • ldap

If you’ve ever worked at IBM then you know what Bluepages is, for those who don’t, it’s the company’s LDAP server. It’s most commonly used via a web interface where employees can look up other employees. Check it out below.

bluepages

As part of my day job I help run the IBM Developer site, which lists a bunch of our Developer Advocates. Recently someone left the company and their page remained until someone made a PR to remove it. I saw this as an opportunity to ideate how I would improve things. A bit of Python and a travis job that runs daily to remove users that are not found should do the trick!

So I quickly wrote some python code using the python-ldap project, which wraps the openLDAP client, so ensure you have those two installed before looking at the Python code below.

# I use a Mac, so brew it is
brew install openldap
pip install python-ldap

Then fire up your favorite editor and write a few lines of code to anonymously bind and look up a user. You can look up a user by email using the email=* query or by name using cn=*.

import ldap

ldap_uri = 'ldap://bluepages.ibm.com'
ldap_base = 'ou=bluepages,o=ibm.com'
#query = "(cn=Steve Martinelli)"
query = "(email=stevemar@caibm.com)"

con = ldap.initialize(ldap_uri)
result = con.search_s(ldap_base, ldap.SCOPE_SUBTREE, query)
print(result)

You’ll get back something like this:

{
  "ou": ["bluepages"],
  "o": ["ibm.com"],
  "co": ["Canada"],
  "emailAddress": ["stevemar@ca.ibm.com"],
  "cn": ["Steve Martinelli"]
}

What I like about the python-ldap library is that it makes things simple. Even after working for years on OpenStack’s Identity service I still scratch my head if given too many prompts.

Hope this helps other IBMers looking to whip up a quick prototype or two!