db_modeling_for_capi #5
@@ -8,6 +8,10 @@ database:
|
|||||||
# AlpineBits Python config
|
# AlpineBits Python config
|
||||||
# Use annotatedyaml for secrets and environment-specific overrides
|
# Use annotatedyaml for secrets and environment-specific overrides
|
||||||
|
|
||||||
|
logger:
|
||||||
|
level: "INFO" # Set to DEBUG for more verbose output
|
||||||
|
file: "alpinebits.log" # Log file path, or null for console only
|
||||||
|
|
||||||
alpine_bits_auth:
|
alpine_bits_auth:
|
||||||
- hotel_id: "39054_001"
|
- hotel_id: "39054_001"
|
||||||
hotel_name: "Bemelmans Post"
|
hotel_name: "Bemelmans Post"
|
||||||
|
|||||||
@@ -164,12 +164,12 @@ async def lifespan(app: FastAPI):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
config = load_config()
|
config = load_config()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
_LOGGER.error(f"Failed to load config: {e!s}")
|
_LOGGER.exception("Failed to load config: ")
|
||||||
config = {}
|
config = {}
|
||||||
|
|
||||||
DATABASE_URL = get_database_url(config)
|
DATABASE_URL = get_database_url(config)
|
||||||
engine = create_async_engine(DATABASE_URL, echo=True)
|
engine = create_async_engine(DATABASE_URL, echo=False)
|
||||||
AsyncSessionLocal = async_sessionmaker(engine, expire_on_commit=False)
|
AsyncSessionLocal = async_sessionmaker(engine, expire_on_commit=False)
|
||||||
|
|
||||||
app.state.engine = engine
|
app.state.engine = engine
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from annotatedyaml.loader import (
|
from annotatedyaml.loader import Secrets
|
||||||
Secrets,
|
from annotatedyaml.loader import load_yaml as load_annotated_yaml
|
||||||
)
|
|
||||||
from annotatedyaml.loader import (
|
|
||||||
load_yaml as load_annotated_yaml,
|
|
||||||
)
|
|
||||||
from voluptuous import (
|
from voluptuous import (
|
||||||
PREVENT_EXTRA,
|
PREVENT_EXTRA,
|
||||||
All,
|
All,
|
||||||
@@ -21,6 +17,15 @@ from voluptuous import (
|
|||||||
database_schema = Schema({Required("url"): str}, extra=PREVENT_EXTRA)
|
database_schema = Schema({Required("url"): str}, extra=PREVENT_EXTRA)
|
||||||
|
|
||||||
|
|
||||||
|
logger_schema = Schema(
|
||||||
|
{
|
||||||
|
Required("level"): str,
|
||||||
|
Optional("file"): str, # If not provided, log to console
|
||||||
|
},
|
||||||
|
extra=PREVENT_EXTRA,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
hotel_auth_schema = Schema(
|
hotel_auth_schema = Schema(
|
||||||
{
|
{
|
||||||
Required("hotel_id"): str,
|
Required("hotel_id"): str,
|
||||||
@@ -42,6 +47,7 @@ config_schema = Schema(
|
|||||||
{
|
{
|
||||||
Required("database"): database_schema,
|
Required("database"): database_schema,
|
||||||
Required("alpine_bits_auth"): basic_auth_schema,
|
Required("alpine_bits_auth"): basic_auth_schema,
|
||||||
|
Optional("logger", default={"level": "INFO", "file": None}): logger_schema,
|
||||||
},
|
},
|
||||||
extra=PREVENT_EXTRA,
|
extra=PREVENT_EXTRA,
|
||||||
)
|
)
|
||||||
@@ -52,7 +58,7 @@ DEFAULT_CONFIG_FILE = "config.yaml"
|
|||||||
class Config:
|
class Config:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config_folder: str | Path = None,
|
config_folder: str | Path | None = None,
|
||||||
config_name: str = DEFAULT_CONFIG_FILE,
|
config_name: str = DEFAULT_CONFIG_FILE,
|
||||||
testing_mode: bool = False,
|
testing_mode: bool = False,
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user