Coverage for src/fastapi_cloud_cli/commands/auth/wait.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-11-09 00:25 +0000

1from typing import Annotated, Any 1abcdefg

2 

3import typer 1abcdefg

4 

5from fastapi_cloud_cli.api import APIClient 1abcdefg

6from fastapi_cloud_cli.commands._flow import ( 1abcdefg

7 DEFAULT_LOGIN_TIMEOUT_SECONDS, 

8 complete_device_login, 

9 render_login_output, 

10) 

11from fastapi_cloud_cli.commands.auth._app import auth_app 1abcdefg

12from fastapi_cloud_cli.utils.cli import get_rich_toolkit 1abcdefg

13from fastapi_cloud_cli.utils.execution import JsonOutputOption 1abcdefg

14 

15 

16@auth_app.command("wait") 1abcdefg

17def wait( 1abXcdYefgZ

18 device_code: Annotated[ 

19 str, 

20 typer.Option( 

21 "--device-code", 

22 help="Device code returned by `fastapi cloud auth login --json`.", 

23 ), 

24 ], 

25 interval: Annotated[ 

26 int, 

27 typer.Option( 

28 "--interval", 

29 help="Seconds between authorization polling attempts.", 

30 min=5, 

31 ), 

32 ] = 5, 

33 timeout: Annotated[ 

34 int, 

35 typer.Option( 

36 "--timeout", 

37 help="Maximum seconds to wait for authorization.", 

38 min=10, 

39 ), 

40 ] = DEFAULT_LOGIN_TIMEOUT_SECONDS, 

41 json_output: JsonOutputOption = False, 

42) -> Any: 

43 """ 

44 Wait for a device authorization flow to complete. 

45 """ 

46 with get_rich_toolkit(json_output=json_output) as toolkit: 1hvwxyijzABCklDEFGmnHIJKopLMNOqrPQRSstTUVWu

47 with APIClient() as client: 1hvwxyijzABCklDEFGmnHIJKopLMNOqrPQRSstTUVWu

48 toolkit.print_title( 1hvwxyijzABCklDEFGmnHIJKopLMNOqrPQRSstTUVWu

49 "Login to FastAPI Cloud", tag="FastAPI Cloud", emoji="🔐" 

50 ) 

51 toolkit.print_line() 1hvwxyijzABCklDEFGmnHIJKopLMNOqrPQRSstTUVWu

52 

53 with toolkit.progress( 1hvwxyijzABCklDEFGmnHIJKopLMNOqrPQRSstTUVWu

54 "Waiting for user to authorize...", transient=True 

55 ) as progress: 

56 result = complete_device_login( 1hvwxyijzABCklDEFGmnHIJKopLMNOqrPQRSstTUVWu

57 client=client, 

58 progress=progress, 

59 toolkit=toolkit, 

60 device_code=device_code, 

61 interval=interval, 

62 timeout=timeout, 

63 cancel_hint="Run `fastapi cloud auth wait --json` again to retry.", 

64 ) 

65 

66 toolkit.success( 1hijklmnopqrstu

67 result, 

68 render_output=render_login_output, 

69 )