config.py 686 B

1234567891011121314151617181920212223242526
  1. import json
  2. from pathlib import Path
  3. from pydantic import BaseModel
  4. from .utils.config import get_cli_config_path
  5. class Settings(BaseModel):
  6. base_api_url: str = "https://api.fastapicloud.com/api/v1"
  7. client_id: str = "fastapi-cli"
  8. @classmethod
  9. def from_user_settings(cls, config_path: Path) -> "Settings":
  10. try:
  11. content = config_path.read_bytes() if config_path.exists() else b"{}"
  12. user_settings = json.loads(content)
  13. except json.JSONDecodeError:
  14. user_settings = {}
  15. return cls(**user_settings)
  16. @classmethod
  17. def get(cls) -> "Settings":
  18. return cls.from_user_settings(get_cli_config_path())