add config
This commit is contained in:
parent
212672957d
commit
0abfa719fa
|
@ -0,0 +1,4 @@
|
|||
OAA_CFG__RUN__HOST=0.0.0.0
|
||||
OAA_CFG__RUN__PORT=8000
|
||||
OAA_CFG__RUN__RELOAD=True
|
||||
OAA_CFG__LOG__LEVEL=20
|
|
@ -0,0 +1,61 @@
|
|||
from pydantic import BaseModel
|
||||
from pydantic_settings import (
|
||||
BaseSettings,
|
||||
SettingsConfigDict,
|
||||
)
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
BASE_DIR = Path(__file__).parent.parent
|
||||
TEMPLATES_DIR = BASE_DIR / "web" / "templates"
|
||||
STATIC_DIR = BASE_DIR / "web" / "static"
|
||||
|
||||
|
||||
class RunConfig(BaseModel):
|
||||
host: str = "0.0.0.0"
|
||||
port: int = 8000
|
||||
reload: bool = False
|
||||
|
||||
|
||||
class LogConfig(BaseModel):
|
||||
level: int = 20
|
||||
datefmt: str = "%Y-%m-%d %H:%M:%S"
|
||||
format: str = (
|
||||
"[%(asctime)s.%(msecs)03d] %(module)-25s:%(lineno)4d | %(funcName)-20s| %(levelname)-8s | %(message)s"
|
||||
)
|
||||
|
||||
|
||||
class SwaggerConfig(BaseModel):
|
||||
openapi_url: str = "/openapi.json"
|
||||
title: str = "API"
|
||||
oauth2_redirect_url: str = "/docs/oauth2-redirect"
|
||||
swagger_js_url: str = "/static/swagger/swagger-ui-bundle.js"
|
||||
swagger_css_url: str = "/static/swagger/swagger-ui.css"
|
||||
swagger_favicon_url: str = "/static/swagger/favicon.png"
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=(
|
||||
BASE_DIR / "config" / ".env-template",
|
||||
BASE_DIR / "config" / ".env",
|
||||
),
|
||||
case_sensitive=False,
|
||||
env_nested_delimiter="__",
|
||||
env_prefix="OAA_CFG__",
|
||||
)
|
||||
run: RunConfig = RunConfig()
|
||||
swagger: SwaggerConfig = SwaggerConfig()
|
||||
log: LogConfig = LogConfig()
|
||||
|
||||
|
||||
conf = Settings()
|
||||
|
||||
logging.basicConfig(
|
||||
level=conf.log.level,
|
||||
datefmt=conf.log.datefmt,
|
||||
format=conf.log.format,
|
||||
)
|
Loading…
Reference in New Issue