SFM/app/core/config.py
2026-09-17 13:04:35 +03:00

42 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
from pydantic import AliasChoices, Field
from pydantic_settings import BaseSettings, SettingsConfigDict
_prefix = "OPENBAO__SETTINGS"
class Settings(BaseSettings):
"""Настройки БД и секретов для хранения токенов OpenCloud заказчиков.
Конвенция (`OPENBAO__SETTINGS__*`, pydantic-settings + AliasChoices)
скопирована с примера DFiP Budget Planning (api/src/core/config.py) —
там она уже проверена в проде для этой же схемы инъекции секретов
через OpenBao.
"""
DATABASE_URL: str = Field(
default="sqlite+aiosqlite:///./sfm_opencloud_tokens.db",
description="URL подключения к БД с таблицей токенов OpenCloud",
validation_alias=AliasChoices(f"{_prefix}__DATABASE_URL", "DATABASE_URL"),
)
DATABASE_SCHEMA: str = Field(
default="",
description="Схема БД (для Postgres search_path), если выделена отдельная",
validation_alias=AliasChoices(f"{_prefix}__DATABASE_SCHEMA", "DATABASE_SCHEMA"),
)
FERNET_KEY: str = Field(
default="",
description=(
"Ключ шифрования токенов OpenCloud (Fernet, urlsafe base64, 32 байта). "
"ОБЯЗАТЕЛЕН в проде — пустое значение допустимо только для локальной "
"разработки, где шифрование токенов не тестируется."
),
validation_alias=AliasChoices(f"{_prefix}__FERNET_KEY", "FERNET_KEY"),
)
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
settings = Settings()