119 lines
3.7 KiB
Python
119 lines
3.7 KiB
Python
import os
|
|
from typing import List
|
|
|
|
from pydantic import AliasChoices, Field
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
prefix = "OPENBAO__SETTINGS"
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Настройки backend для DFiP Budget Planing."""
|
|
|
|
ROOT_PATH: str = Field(default="", description="Префикс API", alias="ROOT_PATH")
|
|
|
|
# Database
|
|
DATABASE_URL: str = Field(
|
|
default="sqlite+aiosqlite:///./dfip_budget_planing.db",
|
|
description="URL подключения к базе данных",
|
|
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"),
|
|
)
|
|
|
|
# JWT
|
|
JWT_SECRET: str = Field(
|
|
default="change-me-in-production",
|
|
description="Секретный ключ для JWT",
|
|
)
|
|
JWT_ALGORITHM: str = Field(default="HS256", description="Алгоритм JWT")
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = Field(
|
|
default=60,
|
|
description="Время жизни access-токена (минуты)",
|
|
)
|
|
REFRESH_TOKEN_EXPIRE_DAYS: int = Field(
|
|
default=7,
|
|
description="Время жизни refresh-токена (дни)",
|
|
)
|
|
|
|
# CORS
|
|
CORS_ORIGINS: List[str] = Field(
|
|
default=[
|
|
"https://raisa.go.rshbank.ru",
|
|
"http://localhost:3000",
|
|
"http://localhost:8080",
|
|
"http://127.0.0.1:3000",
|
|
"http://127.0.0.1:8000",
|
|
],
|
|
description="Разрешенные origins для CORS",
|
|
)
|
|
|
|
HOST: str = Field(
|
|
default="0.0.0.0",
|
|
description="Хост API",
|
|
validation_alias=AliasChoices("SERVER__HOST", "HOST"),
|
|
)
|
|
PORT: int = Field(
|
|
default=8000,
|
|
description="Порт API",
|
|
validation_alias=AliasChoices("SERVER__PORT", "PORT"),
|
|
)
|
|
|
|
# Environment
|
|
ENVIRONMENT: str = Field(
|
|
default="development",
|
|
description="Окружение приложения",
|
|
alias="APP_ENV",
|
|
)
|
|
DEBUG: bool = Field(
|
|
default=True,
|
|
description="Режим отладки",
|
|
validation_alias=AliasChoices(f"{prefix}__DEBUG", "DEBUG"),
|
|
)
|
|
|
|
# Authorization (prod branch)
|
|
JWKS_URL: str = Field(
|
|
default="https://keycloak.raisa.go.rshbank.ru/realms/datalab/protocol/openid-connect/certs",
|
|
description="URL для получения JWKS",
|
|
alias="JWKS_URL",
|
|
)
|
|
APP_NAMESPACE: str = Field(
|
|
default="dfip",
|
|
description="Namespace приложения для protected-api",
|
|
alias="APP_NAMESPACE",
|
|
)
|
|
APP_NAME: str = Field(
|
|
default="dfip_budget_planing_api",
|
|
description="Имя приложения для protected-api",
|
|
alias="APP_NAME",
|
|
)
|
|
|
|
# Audit log
|
|
AUDIT_LOG_RETENTION_DAYS: int = Field(
|
|
default=365,
|
|
description="Удалять записи аудита старше N дней",
|
|
alias="AUDIT_LOG_RETENTION_DAYS",
|
|
)
|
|
AUDIT_LOG_CLEANUP_BATCH_SIZE: int = Field(
|
|
default=5000,
|
|
description="Размер батча для очистки аудита",
|
|
alias="AUDIT_LOG_CLEANUP_BATCH_SIZE",
|
|
)
|
|
AUDIT_LOG_CLEANUP_INTERVAL_SECONDS: int = Field(
|
|
default=86400,
|
|
description="Интервал автозапуска очистки аудита в секундах",
|
|
alias="AUDIT_LOG_CLEANUP_INTERVAL_SECONDS",
|
|
)
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
extra="ignore",
|
|
env_nested_delimiter="__",
|
|
)
|
|
|
|
|
|
settings = Settings()
|