mirror of
https://gitverse.ru/kpa39l/md2vk.git
synced 2026-09-29 09:55:04 +00:00
Baseline md2vk: docs, audit log, docker 8420, openspec, deploy
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""Конфигурация md2vk из переменных окружения."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
# HTTP
|
||||
host: str = "0.0.0.0"
|
||||
port: int = 8000
|
||||
|
||||
# Файл с Fernet-ключом (Docker secret / файл на диске)
|
||||
token_encryption_key_file: str = "/run/secrets/token_encryption_key"
|
||||
|
||||
# База данных
|
||||
database_url: str = "sqlite+aiosqlite:///data/md2vk.db"
|
||||
|
||||
# VK API
|
||||
vk_api_version: str = "5.199"
|
||||
|
||||
# Rate limiting (запросов в минуту на VK-аккаунт)
|
||||
rate_limit_per_minute: int = 10
|
||||
|
||||
model_config = {"env_file": ".env", "env_prefix": ""}
|
||||
|
||||
@property
|
||||
def fernet_key(self) -> bytes:
|
||||
"""Читает и возвращает Fernet-ключ из файла."""
|
||||
key_path = Path(self.token_encryption_key_file)
|
||||
if not key_path.exists():
|
||||
raise RuntimeError(
|
||||
f"Файл с Fernet-ключом не найден: {key_path}. "
|
||||
f"Сгенерируйте: python3 -c \"from cryptography.fernet import Fernet; "
|
||||
f"print(Fernet.generate_key().decode())\" > {key_path}"
|
||||
)
|
||||
return key_path.read_bytes().strip()
|
||||
|
||||
|
||||
settings = Settings()
|
||||
Reference in New Issue
Block a user