From 0ab42c1d75255e96cc7f6e84bb83421a69eb1668 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 11 Oct 2018 11:39:04 +0100 Subject: [PATCH] Use correct python module Signed-off-by: Michael Tremer --- requirements.txt | 3 ++- src/backend/accounts.py | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/requirements.txt b/requirements.txt index f70ac158..35cc3eb4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,6 @@ feedparser==5.2.1 file-magic==0.4.0 html5lib==1.0.1 iso3166==0.9 -ldap==1.0.2 ldap3==2.5.1 markdown2==2.3.6 pciutils==2.3.7 @@ -11,7 +10,9 @@ Pillow==5.3.0 psycopg2-binary==2.7.5 py-dateutil==2.2 pyasn1==0.4.4 +pyasn1-modules==0.2.2 pycurl==7.43.0 +python-ldap==3.1.0 python3-memcached==1.51 six==1.11.0 textile==3.0.3 diff --git a/src/backend/accounts.py b/src/backend/accounts.py index 7490e915..d322198b 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -18,20 +18,19 @@ class Accounts(Object): return iter(sorted(accounts)) - @property + @lazy_property def ldap(self): - if not hasattr(self, "_ldap"): - # Connect to LDAP server - ldap_uri = self.settings.get("ldap_uri") - self._ldap = ldap.initialize(ldap_uri) + # Connect to LDAP server + ldap_uri = self.settings.get("ldap_uri") + conn = ldap.initialize(ldap_uri) - # Bind with username and password - bind_dn = self.settings.get("ldap_bind_dn") - if bind_dn: - bind_pw = self.settings.get("ldap_bind_pw", "") - self._ldap.simple_bind(bind_dn, bind_pw) + # Bind with username and password + bind_dn = self.settings.get("ldap_bind_dn") + if bind_dn: + bind_pw = self.settings.get("ldap_bind_pw", "") + conn.simple_bind(bind_dn, bind_pw) - return self._ldap + return conn def _query(self, query, attrlist=None, limit=0): logging.debug("Performing LDAP query: %s" % query) @@ -43,7 +42,8 @@ class Accounts(Object): query, attrlist=attrlist, sizelimit=limit) except: # Close current connection - del self._ldap + self.ldap.close() + del self.ldap raise -- 2.47.3