Skip to content

Commit 9a7290b

Browse files
authored
Merge pull request #18 from daily-co/jpt/daily_api_key
added method to retrieve Daily API Key
2 parents fc00824 + 1f3c4fc commit 9a7290b

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

src/pipecatcloud/api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ async def _organizations(self) -> list:
168168
def organizations(self):
169169
return self.create_api_method(self._organizations)
170170

171+
# Daily API Key
172+
173+
async def _organizations_daily_key(self, org) -> dict:
174+
url = self.construct_api_url("daily_key_path").format(org=org)
175+
return await self._base_request("GET", url) or {}
176+
177+
@property
178+
def organizations_daily_key(self):
179+
return self.create_api_method(self._organizations_daily_key)
180+
171181
# API Keys
172182

173183
async def _api_keys(self, org) -> dict:

src/pipecatcloud/cli/commands/auth.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import aiohttp
1414
import typer
1515
from loguru import logger
16+
from rich.columns import Columns
1617
from rich.live import Live
1718
from rich.panel import Panel
1819

@@ -151,10 +152,7 @@ async def login():
151152
Panel(
152153
"The web browser should have opened for you to authenticate with Pipecat Cloud.\n"
153154
"If it didn't, please copy this URL into your web browser manually:\n\n"
154-
f"[blue][link={web_url}]{web_url}[/link][/blue]\n",
155-
)
156-
)
157-
)
155+
f"[blue][link={web_url}]{web_url}[/link][/blue]\n", )))
158156
else:
159157
# For headless use-cases, just print the URL
160158
live.stop()
@@ -222,7 +220,7 @@ async def logout():
222220
)
223221

224222

225-
@auth_cli.command(name="whoami", help="Display data about the current user.")
223+
@auth_cli.command(name="whoami", help="Display data about the current user. Also show Daily API key.")
226224
@synchronizer.create_blocking
227225
@requires_login
228226
async def whomai():
@@ -251,11 +249,26 @@ async def whomai():
251249
if not account["name"] or not account["verbose_name"]:
252250
raise
253251

254-
live.stop()
252+
# Retrieve user Daily API key
253+
# Note: we don't raise an error if this fails, as it's not required for
254+
# the CLI to function
255+
live.update(console.status("[dim]Fetching Daily API key...[/dim]", spinner="dots"))
255256

256-
console.success(
257-
f"[bold]User ID:[/bold] {user_data['user']['userId']}\n"
258-
f"[bold]Active Organization:[/bold] {account['verbose_name']} [dim]({account['name']})[/dim]",
259-
)
257+
daily_api_key = None
258+
try:
259+
daily_api_key, error = await API.organizations_daily_key(org=org, live=live)
260+
except Exception:
261+
pass
262+
263+
live.stop()
264+
message = Columns([
265+
"[bold]User ID[/bold]\n"
266+
"[bold]Active Organization[/bold]\n"
267+
"[bold]Daily API Key[/bold]",
268+
f"{user_data['user']['userId']}\n"
269+
f"{account['verbose_name']} [dim]({account['name']})[/dim]\n"
270+
f"{daily_api_key.get('apiKey', '[dim]N/A[/dim]') if daily_api_key else '[dim]N/A[/dim]'}",
271+
])
272+
console.success(message)
260273
except Exception:
261274
console.error("Unable to obtain user data. Please contact support")

src/pipecatcloud/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class _Setting(typing.NamedTuple):
2626
"login_status_path": _Setting("/auth/status"),
2727
"whoami_path": _Setting("/v1/users"),
2828
"organization_path": _Setting("/v1/organizations"),
29+
"daily_key_path": _Setting("/v1/organizations/{org}/daily"),
2930
"services_path": _Setting("/v1/organizations/{org}/services"),
3031
"services_logs_path": _Setting("/v1/organizations/{org}/services/{service}/logs"),
3132
"services_deployments_path": _Setting("/v1/organizations/{org}/services/{service}/deployments"),

0 commit comments

Comments
 (0)