feat: bootstrap backend MVP and architecture docs
This commit is contained in:
46
app/core/config.py
Normal file
46
app/core/config.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from functools import lru_cache
|
||||
from typing import Annotated
|
||||
|
||||
from pydantic import field_validator
|
||||
from pydantic_settings import BaseSettings, NoDecode, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
|
||||
|
||||
app_env: str = "development"
|
||||
port: int = 8000
|
||||
|
||||
db_host: str = "127.0.0.1"
|
||||
db_port: int = 54321
|
||||
db_name: str = "member_center"
|
||||
db_user: str = "member_ose"
|
||||
db_password: str = ""
|
||||
|
||||
authentik_base_url: str = ""
|
||||
authentik_admin_token: str = ""
|
||||
authentik_verify_tls: bool = False
|
||||
|
||||
public_frontend_origins: Annotated[list[str], NoDecode] = ["https://member.ose.tw"]
|
||||
internal_shared_secret: str = ""
|
||||
|
||||
@field_validator("public_frontend_origins", mode="before")
|
||||
@classmethod
|
||||
def parse_origins(cls, value: str | list[str]) -> list[str]:
|
||||
if isinstance(value, list):
|
||||
return value
|
||||
if not value:
|
||||
return []
|
||||
return [origin.strip() for origin in value.split(",") if origin.strip()]
|
||||
|
||||
@property
|
||||
def database_url(self) -> str:
|
||||
return (
|
||||
"postgresql+psycopg://"
|
||||
f"{self.db_user}:{self.db_password}@{self.db_host}:{self.db_port}/{self.db_name}"
|
||||
)
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_settings() -> Settings:
|
||||
return Settings()
|
||||
Reference in New Issue
Block a user