from pydantic_settings import BaseSettings, SettingsConfigDict from fastapi.responses import JSONResponse class Configs(BaseSettings): """ ApiTemplate configuration settings. """ PATH: str = "" HOST: str = "" PORT: int = 0 LOG_LEVEL: str = "info" RELOAD: int = 0 ACCESS_TOKEN_TAG: str = "" ACCESS_EMAIL_EXT: str = "" TITLE: str = "" ALGORITHM: str = "" ACCESS_TOKEN_LENGTH: int = 90 REFRESHER_TOKEN_LENGTH: int = 144 EMAIL_HOST: str = "" DATETIME_FORMAT: str = "" FORGOT_LINK: str = "" ALLOW_ORIGINS: list = ["http://localhost:3000"] VERSION: str = "0.1.001" DESCRIPTION: str = "" @property def app_as_dict(self) -> dict: """ Convert the settings to a dictionary. """ return { "app": self.PATH, "host": self.HOST, "port": int(self.PORT), "log_level": self.LOG_LEVEL, "reload": bool(self.RELOAD), } @property def api_info(self): """ Returns a dictionary with application information. """ return { "title": self.TITLE, "description": self.DESCRIPTION, "default_response_class": JSONResponse, "version": self.VERSION, } @classmethod def forgot_link(cls, forgot_key): """ Generate a forgot password link. """ return cls.FORGOT_LINK + forgot_key model_config = SettingsConfigDict(env_prefix="API_") api_config = Configs()