Page MenuHomePhorge

D1690.id4498.diff
No OneTemporary

D1690.id4498.diff

diff --git a/pykolab/auth/ldap/auth_cache.py b/pykolab/auth/ldap/auth_cache.py
--- a/pykolab/auth/ldap/auth_cache.py
+++ b/pykolab/auth/ldap/auth_cache.py
@@ -17,6 +17,7 @@
#
import datetime
+import os
import sqlalchemy
@@ -84,6 +85,11 @@
db = init_db()
+ if db is None:
+ return
+
+ purge_entries()
+
try:
db.query(Entry).filter_by(key=key).delete()
except sqlalchemy.exc.OperationalError:
@@ -102,6 +108,9 @@
db = init_db()
+ if db is None:
+ return None
+
try:
_entries = db.query(Entry).filter_by(key=key).all()
except sqlalchemy.exc.OperationalError:
@@ -111,18 +120,32 @@
finally:
_entries = db.query(Entry).filter_by(key=key).all()
- if len(_entries) != 1:
+ __entries = []
+
+ for __entry in _entries:
+ if __entry.last_change <= datetime.datetime.now() - datetime.timedelta(0, 7200):
+ continue
+
+ __entries.append(__entry)
+
+ if len(__entries) != 1:
return None
- log.debug("Entry found: %r" % (_entries[0].__dict__))
- log.debug("Returning: %r" % (_entries[0].value))
+ log.debug("Entry found: %r" % (__entries[0].__dict__))
+ log.debug("Returning: %r" % (__entries[0].value))
- return _entries[0].value.encode('utf-8', 'latin1')
+ return __entries[0].value.encode('utf-8', 'latin1')
def set_entry(key, value):
+ # pylint: disable=global-statement
+ global db
+
db = init_db()
+ if db is None:
+ return
+
try:
_entries = db.query(Entry).filter_by(key=key).all()
except sqlalchemy.exc.OperationalError:
@@ -147,12 +170,18 @@
db.commit()
-def purge_entries(db):
- db.query(Entry).filter(
- Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(1))
- ).delete()
+def purge_entries():
+ # pylint: disable=global-statement
+ global db
- db.commit()
+ try:
+ db.query(Entry).filter(
+ Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(0, 7200))
+ ).delete()
+
+ db.commit()
+ except Exception:
+ return
def init_db(reinit=False):
@@ -167,11 +196,13 @@
db_uri = conf.get('ldap', 'auth_cache_uri')
+ if db_uri == "null":
+ return None
+
if db_uri is None:
db_uri = 'sqlite:///%s/auth_cache.db' % (KOLAB_LIB_PATH)
if reinit:
- import os
if os.path.isfile('%s/auth_cache.db' % (KOLAB_LIB_PATH)):
os.unlink('%s/auth_cache.db' % (KOLAB_LIB_PATH))
@@ -181,6 +212,5 @@
Session = sessionmaker(bind=engine)
db = Session()
- purge_entries(db)
return db

File Metadata

Mime Type
text/plain
Expires
Thu, Oct 31, 8:37 AM (10 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10075149
Default Alt Text
D1690.id4498.diff (2 KB)

Event Timeline