48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
from functools import lru_cache
|
|
|
|
from pydantic import Field
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
extra="ignore",
|
|
)
|
|
|
|
app_name: str = "aiclient-api"
|
|
debug: bool = False
|
|
|
|
mysql_host: str = "127.0.0.1"
|
|
mysql_port: int = 3306
|
|
mysql_user: str = "root"
|
|
mysql_password: str = ""
|
|
mysql_database: str = "aiclient"
|
|
|
|
redis_url: str = "redis://127.0.0.1:6379/0"
|
|
|
|
secret_key: str = Field(default="change-me-in-production")
|
|
access_token_expire_minutes: int = 60 * 24 * 7
|
|
|
|
cors_origins: str = "http://localhost:1420"
|
|
|
|
@property
|
|
def database_url(self) -> str:
|
|
return (
|
|
f"mysql+aiomysql://{self.mysql_user}:{self.mysql_password}"
|
|
f"@{self.mysql_host}:{self.mysql_port}/{self.mysql_database}"
|
|
)
|
|
|
|
@property
|
|
def cors_origin_list(self) -> list[str]:
|
|
raw = self.cors_origins.strip()
|
|
if raw == "*":
|
|
return ["*"]
|
|
return [o.strip() for o in raw.split(",") if o.strip()]
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
return Settings()
|