[PATCH 3 of 5 3.27] [ldapfeed] make code compatible with ldap3>=2

Nicolas Chauvat nicolas.chauvat at logilab.fr
Thu Feb 27 01:30:25 CET 2020


Hi Philippe,

Nice to see this upgrade.

On Wed, Feb 26, 2020 at 04:14:26PM +0100, Philippe Pepiot wrote:
> @@ -267,17 +266,26 @@ You can set multiple groups by separatin
>      def _connect(self, user=None, userpwd=None):
>          protocol, host, port = self.connection_info()
>          self.info('connecting %s://%s:%s as %s', protocol, host, port,
> -                  user and user['dn'] or 'anonymous')
> +                  user and user['dn'] or self.cnx_dn or 'anonymous')
>          server = ldap3.Server(host, port=int(port))
> +        kwargs = {}
> +        if user:
> +            kwargs['user'] = user['dn']
> +        elif self.cnx_dn:
> +            kwargs['user'] = self.cnx_dn
> +            if self.cnx_pwd:
> +                kwargs['password'] = self.cnx_pwd
>          conn = ldap3.Connection(
> -            server, user=user and user['dn'],
> -            client_strategy=ldap3.STRATEGY_SYNC_RESTARTABLE,
> -            auto_referrals=False)
> +            server, client_strategy=ldap3.RESTARTABLE, auto_referrals=False,
> +            raise_exceptions=True,
> +            **kwargs)

The info message looks brittle. I would suggest to reorder the lines:

    def _connect(self, user=None, userpwd=None):
        protocol, host, port = self.connection_info()
        kwargs = {}
        if user:
            kwargs['user'] = user['dn']
        elif self.cnx_dn:
            kwargs['user'] = self.cnx_dn
            if self.cnx_pwd:
                kwargs['password'] = self.cnx_pwd
        self.info('connecting %s://%s:%s as %s', protocol, host, port,
                  kwargs.get('user', 'anonymous'))
        server = ldap3.Server(host, port=int(port))
        conn = ldap3.Connection(
            server, client_strategy=ldap3.RESTARTABLE, auto_referrals=False,
            raise_exceptions=True,
            **kwargs)

I read the rest of the pile and it looked good. I did not test it. Do
you have a link to a jenkins job that ran that code?

-- 
Nicolas Chauvat

logilab.fr - services en informatique scientifique et gestion de connaissances  



More information about the cubicweb-devel mailing list