@@ -90,6 +90,20 @@ async def delete_jwk(args):
9090 save_jwks (path , jwks )
9191
9292
93+ async def cleanup_authdb (args ):
94+ """Delete expired tokens and flows from the AuthDB."""
95+ logger .info ("Deleting expired tokens and flows" )
96+ from diracx .core .settings import AuthSettings
97+ from diracx .db .sql import AuthDB
98+ from diracx .logic .auth .management import cleanup_expired_data
99+
100+ settings = AuthSettings ()
101+ db = AuthDB (args .db_url )
102+ async with db .engine_context ():
103+ async with db :
104+ await cleanup_expired_data (db , settings )
105+
106+
93107def parse_args ():
94108 parser = argparse .ArgumentParser ()
95109 subparsers = parser .add_subparsers (dest = "command" , required = True )
@@ -120,8 +134,16 @@ def parse_args():
120134 )
121135 delete_jwk_parser .set_defaults (func = delete_jwk )
122136
137+ cleanup_authdb_parser = subparsers .add_parser (
138+ "cleanup-authdb" , help = "Delete expired tokens and flows from the AuthDB"
139+ )
140+ cleanup_authdb_parser .add_argument (
141+ "--db-url" , required = True , help = "URL to the AuthDB"
142+ )
143+ cleanup_authdb_parser .set_defaults (func = cleanup_authdb )
144+
123145 args = parser .parse_args ()
124- logger . setLevel ( logging .INFO )
146+ logging . basicConfig ( level = logging .INFO )
125147 asyncio .run (args .func (args ))
126148
127149
0 commit comments