36 lines
925 B
Python
36 lines
925 B
Python
from functools import lru_cache
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
|
|
|
|
db_host: str = "127.0.0.1"
|
|
db_port: int = 3306
|
|
db_user: str = "root"
|
|
db_password: str = ""
|
|
db_name: str = "radius"
|
|
|
|
cors_origins: str = "*"
|
|
default_limit: int = 50
|
|
max_limit: int = 500
|
|
|
|
@property
|
|
def database_url(self) -> str:
|
|
from urllib.parse import quote_plus
|
|
|
|
return (
|
|
f"mysql+pymysql://{self.db_user}:{quote_plus(self.db_password)}"
|
|
f"@{self.db_host}:{self.db_port}/{self.db_name}?charset=utf8mb4"
|
|
)
|
|
|
|
@property
|
|
def cors_origin_list(self) -> list[str]:
|
|
return [o.strip() for o in self.cors_origins.split(",") if o.strip()]
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
return Settings()
|