videosdkagent-cli 0.0.1__py2.py3-none-any.whl → 0.0.4__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
videosdk_cli/auth.py CHANGED
@@ -1,57 +1,122 @@
1
1
  import asyncio
2
2
  import click
3
- from videosdk_cli.utils.config_manager import get_config_value, set_config_value
4
- from videosdk_cli.utils.api_client import VideoSDKClient
3
+ from videosdk_cli.utils.config_manager import set_config_value
5
4
  from videosdk_cli.utils.auth_api_client import AuthAPIClient
5
+ from videosdk_cli.utils.ui.theme import (
6
+ console,
7
+ print_header,
8
+ print_success,
9
+ print_info,
10
+ PRIMARY,
11
+ MUTED,
12
+ )
6
13
  import os
7
14
  import webbrowser
8
15
 
16
+
17
+ @click.group()
18
+ def auth_cli():
19
+ """
20
+ Authenticate with VideoSDK.
21
+
22
+ Login or logout from your VideoSDK account. Authentication is required
23
+ for deploying and managing agents.
24
+
25
+ \b
26
+ Commands:
27
+ login Authenticate with your VideoSDK account
28
+ logout Remove stored authentication token
29
+ """
30
+ pass
31
+
32
+
33
+ @auth_cli.command(name="login")
34
+ def login():
35
+ """
36
+ Login to your VideoSDK account.
37
+
38
+ Opens a browser window for authentication. After successful login,
39
+ your credentials are stored locally for future CLI commands.
40
+
41
+ \b
42
+ Example:
43
+ $ videosdk auth login
44
+ """
45
+ try:
46
+ asyncio.run(handle_auth())
47
+ except KeyboardInterrupt:
48
+ console.print(f"\n[{PRIMARY}]Authentication cancelled by user[/{PRIMARY}]")
49
+ except Exception as e:
50
+ raise click.ClickException(f"Authentication failed: Please try again")
51
+
52
+
53
+ @auth_cli.command(name="logout")
54
+ def logout():
55
+ """
56
+ Logout from your VideoSDK account.
57
+
58
+ Removes the stored authentication token. You will need to login
59
+ again to use authenticated commands.
60
+
61
+ \b
62
+ Example:
63
+ $ videosdk auth logout
64
+ """
65
+ try:
66
+ asyncio.run(handle_logout())
67
+ except KeyboardInterrupt:
68
+ console.print(f"\n[{PRIMARY}]Logout cancelled by user[/{PRIMARY}]")
69
+ except Exception as e:
70
+ raise click.ClickException(f"Logout failed: Please try again")
71
+
72
+
9
73
  async def handle_auth():
10
- API_BASE_URL = os.environ.get("API_BASE_URL","http://localhost:8000")
11
- client = AuthAPIClient(API_BASE_URL)
12
- click.echo("ℹ Initiating browser authentication...")
74
+ from videosdk_cli.utils.template_helper import API_BASE_URL, DASHBOARD_URL
75
+
76
+ client = AuthAPIClient(api_base_url=API_BASE_URL)
77
+
78
+ print_header("Authentication")
79
+ print_info("Initiating browser authentication...")
13
80
 
14
81
  data = await client.start_auth()
15
82
 
16
- generated_url= os.environ.get("AUTH_DASHBOARD_URL","http://localhost:4949") + f"/cli/confirm-auth?requestId={data['requestId']}"
83
+ generated_url = DASHBOARD_URL + "/cli/confirm-auth?requestId=" + data["requestId"]
17
84
  webbrowser.open(generated_url)
18
85
 
19
- click.echo(f"Opened <{generated_url}> in your default browser.\n")
86
+ print_success(f"Opened authentication URL in browser")
87
+ console.print(f" [{MUTED}]{generated_url}[/{MUTED}]")
88
+ console.print()
20
89
 
21
90
  requestId = data["requestId"]
22
91
  expires_in = data["expiresIn"]
23
92
 
24
- spinner = ["|", "/", "-", "\\"]
25
93
  poll_interval = 3
26
94
  attempts = expires_in // poll_interval
27
95
 
28
- click.echo("Waiting for authentication... ", nl=False)
96
+ with console.status(
97
+ f"[{PRIMARY}]Waiting for authentication...[/{PRIMARY}]", spinner="dots"
98
+ ) as status:
99
+ for i in range(attempts):
100
+ await asyncio.sleep(poll_interval)
29
101
 
30
- for i in range(attempts):
31
- click.echo(spinner[i % len(spinner)], nl=False)
32
- click.echo("\b", nl=False)
33
- await asyncio.sleep(poll_interval)
102
+ auth_status = await client.check_status(requestId)
34
103
 
35
- status = await client.check_status(requestId)
104
+ if auth_status["status"] == "approved":
105
+ set_config_value("VIDEOSDK_AUTH_TOKEN", auth_status["token"])
106
+ status.stop()
107
+ print_success("Successfully authenticated!")
108
+ return
36
109
 
37
- if status["status"] == "approved":
38
- set_config_value("VIDEOSDK_AUTH_TOKEN", status["token"])
110
+ if auth_status["status"] == "expired":
111
+ status.stop()
112
+ raise click.ClickException(
113
+ "Authentication link expired. Please run `videosdk auth login` again."
114
+ )
39
115
 
40
- click.echo(
41
- f"\n✔ Successfully authenticated)"
42
- )
43
- return
116
+ raise click.ClickException("Authentication timed out. Please try again.")
44
117
 
45
- if status["status"] == "expired":
46
- raise click.ClickException(
47
- "Authentication link expired. Please run `videosdk auth` again."
48
- )
49
-
50
- raise click.ClickException(
51
- "Authentication timed out. Please try again."
52
- )
53
118
 
54
119
  async def handle_logout():
120
+ print_header("Logout")
55
121
  set_config_value("VIDEOSDK_AUTH_TOKEN", None)
56
- click.echo("Successfully logged out.")
57
-
122
+ print_success("Successfully logged out")