@@ -142,9 +142,9 @@ async def list_tokens() -> None:
142142async def deactivate_token (token_id : int ) -> None :
143143 """Deactivate an authentication token."""
144144 # Ensure database tables exist
145- await create_tables ()
145+ await db_manager . create_tables ()
146146
147- async with AsyncSessionLocal () as db :
147+ async with db_manager . AsyncSession () as db :
148148 try :
149149 success = await crud .deactivate_auth_token (db , token_id )
150150 if success :
@@ -160,9 +160,9 @@ async def deactivate_token(token_id: int) -> None:
160160
161161async def reactivate_token (token_id : int ) -> None :
162162 """Reactivate a deactivated authentication token."""
163- await create_tables ()
163+ await db_manager . create_tables ()
164164
165- async with AsyncSessionLocal () as db :
165+ async with db_manager . AsyncSession () as db :
166166 try :
167167 result = await db .execute (
168168 select (models .AuthToken ).where (models .AuthToken .id == token_id )
@@ -190,9 +190,9 @@ async def update_token_info(
190190 token_id : int , name : str = None , description : str = None
191191) -> None :
192192 """Update token name and/or description."""
193- await create_tables ()
193+ await db_manager . create_tables ()
194194
195- async with AsyncSessionLocal () as db :
195+ async with db_manager . AsyncSession () as db :
196196 try :
197197 result = await db .execute (
198198 select (models .AuthToken ).where (models .AuthToken .id == token_id )
@@ -233,9 +233,9 @@ async def search_tokens(
233233 inactive_only : bool = False ,
234234) -> None :
235235 """Search tokens by name or description patterns."""
236- await create_tables ()
236+ await db_manager . create_tables ()
237237
238- async with AsyncSessionLocal () as db :
238+ async with db_manager . AsyncSession () as db :
239239 try :
240240 query = select (models .AuthToken )
241241
@@ -251,9 +251,9 @@ async def search_tokens(
251251 )
252252
253253 if active_only :
254- conditions .append (models .AuthToken .is_active == True )
254+ conditions .append (models .AuthToken .is_active . is_ ( True ) )
255255 elif inactive_only :
256- conditions .append (models .AuthToken .is_active == False )
256+ conditions .append (models .AuthToken .is_active . is_ ( False ) )
257257
258258 if conditions :
259259 query = query .where (and_ (* conditions ))
@@ -308,9 +308,9 @@ async def search_tokens(
308308
309309async def show_token_details (token_id : int ) -> None :
310310 """Show detailed information about a specific token."""
311- await create_tables ()
311+ await db_manager . create_tables ()
312312
313- async with AsyncSessionLocal () as db :
313+ async with db_manager . AsyncSession () as db :
314314 try :
315315 result = await db .execute (
316316 select (models .AuthToken ).where (models .AuthToken .id == token_id )
@@ -349,17 +349,17 @@ async def show_token_details(token_id: int) -> None:
349349
350350async def show_token_analytics () -> None :
351351 """Show analytics and statistics about token usage."""
352- await create_tables ()
352+ await db_manager . create_tables ()
353353
354- async with AsyncSessionLocal () as db :
354+ async with db_manager . AsyncSession () as db :
355355 try :
356356 # Get basic counts
357357 total_result = await db .execute (select (func .count (models .AuthToken .id )))
358358 total_tokens = total_result .scalar ()
359359
360360 active_result = await db .execute (
361361 select (func .count (models .AuthToken .id )).where (
362- models .AuthToken .is_active == True
362+ models .AuthToken .is_active . is_ ( True )
363363 )
364364 )
365365 active_tokens = active_result .scalar ()
@@ -456,11 +456,11 @@ async def show_token_analytics() -> None:
456456
457457async def cleanup_old_tokens (days : int = 90 , dry_run : bool = True ) -> None :
458458 """Clean up unused tokens older than specified days."""
459- await create_tables ()
459+ await db_manager . create_tables ()
460460
461461 cutoff_date = datetime .utcnow () - timedelta (days = days )
462462
463- async with AsyncSessionLocal () as db :
463+ async with db_manager . AsyncSession () as db :
464464 try :
465465 # Find tokens that are either never used and old, or inactive and old
466466 result = await db .execute (
@@ -476,7 +476,7 @@ async def cleanup_old_tokens(days: int = 90, dry_run: bool = True) -> None:
476476 result2 = await db .execute (
477477 select (models .AuthToken ).where (
478478 and_ (
479- models .AuthToken .is_active == False ,
479+ models .AuthToken .is_active . is_ ( False ) ,
480480 models .AuthToken .created_at < cutoff_date ,
481481 )
482482 )
@@ -547,13 +547,13 @@ async def export_tokens(
547547 format_type : str = "json" , include_inactive : bool = True
548548) -> None :
549549 """Export token information (excluding actual token values)."""
550- await create_tables ()
550+ await db_manager . create_tables ()
551551
552- async with AsyncSessionLocal () as db :
552+ async with db_manager . AsyncSession () as db :
553553 try :
554554 query = select (models .AuthToken )
555555 if not include_inactive :
556- query = query .where (models .AuthToken .is_active == True )
556+ query = query .where (models .AuthToken .is_active . is_ ( True ) )
557557
558558 query = query .order_by (models .AuthToken .created_at )
559559 result = await db .execute (query )
@@ -672,9 +672,7 @@ def main():
672672 )
673673
674674 # List tokens command
675- list_parser = subparsers .add_parser (
676- "list" , help = "List all existing authentication tokens"
677- )
675+ subparsers .add_parser ("list" , help = "List all existing authentication tokens" )
678676
679677 # Show token details command
680678 details_parser = subparsers .add_parser (
@@ -724,7 +722,7 @@ def main():
724722 )
725723
726724 # Analytics command
727- analytics_parser = subparsers .add_parser (
725+ subparsers .add_parser (
728726 "analytics" , help = "Show token usage analytics and statistics"
729727 )
730728
0 commit comments