58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
# app/core/config.py
|
|
import secrets
|
|
from typing import Any, Dict, List, Optional, Union
|
|
|
|
from pydantic import AnyHttpUrl, PostgresDsn, validator
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
API_V1_STR: str = "/api"
|
|
SECRET_KEY: str = secrets.token_urlsafe(32)
|
|
# 60 minutes * 24 hours * 8 days = 8 days
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
|
|
SERVER_NAME: str = "HouseHold API"
|
|
SERVER_HOST: AnyHttpUrl = "http://localhost:8000"
|
|
# BACKEND_CORS_ORIGINS is a JSON-formatted list of origins
|
|
# e.g: ''
|
|
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
|
|
|
|
@validator("BACKEND_CORS_ORIGINS", pre=True)
|
|
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
|
|
if isinstance(v, str) and not v.startswith("["):
|
|
return [i.strip() for i in v.split(",")]
|
|
elif isinstance(v, (list, str)):
|
|
return v
|
|
raise ValueError(v)
|
|
|
|
PROJECT_NAME: str = "HouseHold API"
|
|
|
|
POSTGRES_SERVER: str = "localhost"
|
|
POSTGRES_USER: str = "postgres"
|
|
POSTGRES_PASSWORD: str = "postgres"
|
|
POSTGRES_DB: str = "household"
|
|
SQLALCHEMY_DATABASE_URI: Optional[PostgresDsn] = None
|
|
|
|
@validator("SQLALCHEMY_DATABASE_URI", pre=True)
|
|
def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any:
|
|
if isinstance(v, str):
|
|
return v
|
|
return PostgresDsn.build(
|
|
scheme="postgresql+asyncpg",
|
|
username=values.get("POSTGRES_USER"),
|
|
password=values.get("POSTGRES_PASSWORD"),
|
|
host=values.get("POSTGRES_SERVER"),
|
|
path=f"/{values.get('POSTGRES_DB') or ''}",
|
|
)
|
|
|
|
# OCR Service
|
|
OCR_API_KEY: Optional[str] = None
|
|
OCR_SERVICE_URL: Optional[str] = None
|
|
|
|
class Config:
|
|
case_sensitive = True
|
|
env_file = ".env"
|
|
|
|
|
|
settings = Settings()
|