Files

42 lines
1.3 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.
"""Конфигурация 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()