mirror of
https://gitverse.ru/kpa39l/md2vk.git
synced 2026-09-29 18:05:04 +00:00
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""Конфигурация 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() |