whoami.py 802 B

123456789101112131415161718192021222324252627
  1. import logging
  2. from typing import Any
  3. from rich import print
  4. from rich_toolkit.progress import Progress
  5. from fastapi_cloud_cli.utils.api import APIClient
  6. from fastapi_cloud_cli.utils.auth import is_logged_in
  7. from fastapi_cloud_cli.utils.cli import handle_http_errors
  8. logger = logging.getLogger(__name__)
  9. def whoami() -> Any:
  10. if not is_logged_in():
  11. print("No credentials found. Use [blue]`fastapi login`[/] to login.")
  12. return
  13. with APIClient() as client:
  14. with Progress(title="⚡ Fetching profile", transient=True) as progress:
  15. with handle_http_errors(progress, message=""):
  16. response = client.get("/users/me")
  17. response.raise_for_status()
  18. data = response.json()
  19. print(f"⚡ [bold]{data['email']}[/bold]")