-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathwhoami.py
More file actions
35 lines (26 loc) · 1.07 KB
/
whoami.py
File metadata and controls
35 lines (26 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import logging
from typing import Any
from rich import print
from rich_toolkit.progress import Progress
from fastapi_cloud_cli.context import ctx
from fastapi_cloud_cli.utils.api import APIClient
from fastapi_cloud_cli.utils.cli import handle_http_errors
logger = logging.getLogger(__name__)
def whoami() -> Any:
identity = ctx.get_identity()
if not identity.is_logged_in():
print("No credentials found. Use [blue]`fastapi login`[/] to login.")
else:
with APIClient() as client:
with Progress(title="⚡ Fetching profile", transient=True) as progress:
with handle_http_errors(progress, default_message=""):
response = client.get("/users/me")
response.raise_for_status()
data = response.json()
print(f"⚡ [bold]{data['email']}[/bold]")
# Deployment token status
if identity.deploy_token is not None:
print(
"⚡ [bold]Using API token from environment variable for "
"[blue]`fastapi deploy`[/blue] command.[/bold]"
)