Commit 6f794a7d authored by Jonathan Schaeffer's avatar Jonathan Schaeffer
Browse files

Cleanup method OK

parent 1bae164e
......@@ -10,6 +10,7 @@ from flask import Flask, request, Response
import configurations
import psycopg2
from version import __version__
from psycopg2.extensions import AsIs
application = Flask(__name__)
if 'RUNMODE' in os.environ and os.environ['RUNMODE'] == 'production':
......@@ -153,16 +154,12 @@ def cleanup():
raise e
cur.execute("select user_index,login from users where expires_at < now();")
old_users_entries = cur.fetchall()
old_users_entries = cur.fetchall()[:1000]
old_users = ','.join( str(u[0]) for u in old_users_entries )
logging.debug("%d users to delete : %s"%(len(old_users_entries), old_users))
logging.debug("%d users to delete"%(len(old_users_entries)))
try :
cur.execute("""
delete from credentials where user_index in (%s)
""", old_users)
cur.execute("""
delete from users where user_index in (%s)
""", old_users)
cur.execute("delete from credentials where user_index in (%s);",(AsIs(old_users),))
cur.execute("delete from users where user_index in (%s);", (AsIs(old_users),))
except Exception as e:
logging.error("Unable de delete from credentials or users")
logging.error(e)
......@@ -184,12 +181,13 @@ def cleanup():
application.config['PRIVILEGEDBPORT']))
raise e
logging.debug("Deleting from privileges database")
old_users = ','.join(str(u[1]) for u in old_users_entries)
cur.execute("""
delete from eida_temp_users where name in (%s);
""", ','.join(str(u[1]) for u in old_users_entries))
""", (old_users,))
conn.commit()
conn.close()
return Response("Deleted %d temporary accounts."%(len(users)), status=200)
return Response("Deleted %d temporary accounts."%(len(old_users_entries)), status=200)
@application.route("/", methods=['POST'])
def auth():
......
......@@ -14,7 +14,6 @@ itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
more-itertools==6.0.0
PACKAGENAME==0.0.0
pkginfo==1.5.0.1
pluggy==0.9.0
psycopg2-binary==2.7.7
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment