#51 Be more verbose when logging errors in info LDAP plugin
Closed 8 years ago by puiterwijk. Opened 8 years ago by rcritten.
rcritten/ipsilon ldaperrors  into  master

file modified
+28 -5
@@ -139,25 +139,48 @@ 

          reply = dict()

          try:

              ldapattrs = self._get_user_data(conn, dn)

-             self.debug(ldapattrs)

+             self.debug('LDAP attrs for %s: %s' % (dn, ldapattrs))

              userattrs, extras = self.mapper.map_attributes(ldapattrs)

              groups = self._get_user_groups(conn, base, username)

              reply = userattrs

              reply['_groups'] = groups

              reply['_extras'] = {'ldap': extras}

          except Exception, e:  # pylint: disable=broad-except

-             self.error(e)

+             self.error('Error fetching/mapping LDAP user data: %s' % e)

  

          return reply

  

      def get_user_attrs(self, user):

          try:

-             conn = self._ldap_bind()

              dn = self.user_dn_tmpl % {'username': user}

+         except ValueError as e:

+             self.error(

+                 'DN generation failed with template %s, user %s: %s'

+                 % (self.user_dn_tmpl, user, e)

+             )

+             return {}

+         except Exception as e:  # pylint: disable=broad-except

+             self.error(

+                 'Unhandled error generating DN from %s, user %s: %s'

+                 % (self.user_dn_tmpl, user, e)

+             )

+             return {}

+ 

+         try:

+             conn = self._ldap_bind()

              base = self.base_dn

              return self.get_user_data_from_conn(conn, dn, base, user)

-         except Exception, e:  # pylint: disable=broad-except

-             self.error(e)

+         except ldap.LDAPError as e:

+             self.error(

+                 'LDAP search failed for DN %s on base %s: %s' %

+                 (dn, base, e)

+             )

+             return {}

+         except Exception as e:  # pylint: disable=broad-except

+             self.error(

+                 'Unhandled LDAP error for DN %s on base %s: %s' %

+                 (dn, base, e)

+             )

              return {}

  

  

file modified
+6 -1
@@ -233,7 +233,12 @@ 

                  opts['ldap_bind_dn_template'] % {'username': 'test'}

              except KeyError:

                  logging.error(

-                     'Bind DN template does not container %(username)s'

+                     'Bind DN template does not contain %(username)s'

+                 )

+                 return False

+             except ValueError as e:

+                 logging.error(

+                     'Invalid syntax in Bind DN template: %s ' % e

                  )

                  return False

              config['bind dn template'] = opts['ldap_bind_dn_template']

no initial comment

Please note that this breaks lint (and as such test suite).
I have changed all %'s in the logging calls to commas to make logging lazy.

Well, not all, but only the one in authldap, as that's using logging., and a such triggers the pep8 error.