change(usermaint): converted to use aurweb.db ORM

- Removed usermaint sharness test

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-22 10:51:44 -08:00
parent 8d5683d3f1
commit d097799b34
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
3 changed files with 89 additions and 61 deletions

View file

@ -1,21 +1,31 @@
#!/usr/bin/env python3
import time
from datetime import datetime
import aurweb.db
from sqlalchemy import update
from aurweb import db
from aurweb.models import User
def _main():
limit_to = int(datetime.utcnow().timestamp()) - 86400 * 7
update_ = update(User).where(
User.LastLogin < limit_to
).values(LastLoginIPAddress=None)
db.get_session().execute(update_)
update_ = update(User).where(
User.LastSSHLogin < limit_to
).values(LastSSHLoginIPAddress=None)
db.get_session().execute(update_)
def main():
conn = aurweb.db.Connection()
limit_to = int(time.time()) - 86400 * 7
conn.execute("UPDATE Users SET LastLoginIPAddress = NULL " +
"WHERE LastLogin < ?", [limit_to])
conn.execute("UPDATE Users SET LastSSHLoginIPAddress = NULL " +
"WHERE LastSSHLogin < ?", [limit_to])
conn.commit()
conn.close()
db.get_engine()
with db.begin():
_main()
if __name__ == '__main__':