Skip to content
Snippets Groups Projects
Unverified Commit 1189602a authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

authenticator: Renew the credentials every 15 minutes

Refresh the data from DB every 15 minutes. If it fails, try again next
time.
parent 8edd2fde
No related branches found
No related tags found
1 merge request!8Auth cache
......@@ -19,6 +19,7 @@
#
from twisted.internet import protocol, reactor
from twisted.internet.task import LoopingCall
from twisted.protocols import basic
import re
import psycopg2
......@@ -54,11 +55,24 @@ def renew():
cursor.execute('SELECT name, passwd, mechanism, builtin_passwd, slot_id FROM clients')
lines = cursor.fetchall()
global cred_cache
# This should replace the whole dictionary atomically.
cred_cache = dict(map(lambda l: (l[0], l[1:]), lines))
db.rollback()
print "Caching done"
renew()
def renew_safe():
try:
renew()
except Exception as e:
print "Failed to cache data: " + str(e)
# Reconnect the database, it may have been because of that
openDB()
renew_timer = LoopingCall(renew_safe)
renew_timer.start(900, False)
class AuthClient(basic.LineReceiver):
def connectionMade(self):
self.delimiter = "\n"
......@@ -73,7 +87,6 @@ class AuthClient(basic.LineReceiver):
if match:
mode, client, challenge, response = match.groups()
log_info = cred_cache.get(client)
db.rollback()
if log_info:
if log_info[1] == 'Y': # Always answer yes, DEBUG ONLY!
print "Debug YES"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment