/
artyuhovs
/
AIFeedBackTrainingBot
Обзор
Документация
Войти
/
artyuhovs
/
AIFeedBackTrainingBot
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/devtools.py
66 строк
2 KB
Codex
Завершить архитектурное оздоровление и исправить итоги
15 июл 2026, 11:05
15 июл 2026, 11:05
c65f9a6
Код
Авторство
О чём код?
from __future__ import annotations import json from datetime import UTC, datetime from app.config import Settings from app.db.repositories import Repositories from app.version import APP_VERSION PRODUCTION_CONFIRMATION = "ALLOW_PRODUCTION_TEST_DATA" def record_devtool_event( repository: Repositories, *, tool: str, operation: str, result: str, details: dict[str, object], ) -> None: """Audit a devtool mutation without storing usernames or user content.""" payload = {"tool": tool, "operation": operation, **details} with repository.database.transaction() as db: db.execute( """ INSERT INTO audit_events (event_type, result, release, details_json, created_at) VALUES ('devtool_mutation', ?, ?, ?, ?) """, ( result, APP_VERSION, json.dumps(payload, ensure_ascii=False), datetime.now(UTC).isoformat(), ), ) def authorize_test_data_write( settings: Settings, repository: Repositories, *, tool: str, allow_production: bool, confirmation: str | None, ) -> None: if settings.app_env != "production": return if not allow_production or confirmation != PRODUCTION_CONFIRMATION: raise RuntimeError( "Test-data tools are blocked in production. Both --allow-production and " f"--confirm-production {PRODUCTION_CONFIRMATION} are required." ) with repository.database.connect() as db: db.execute( """ INSERT INTO audit_events (event_type, result, release, details_json, created_at) VALUES ('production_test_data_override', 'authorized', ?, ?, ?) """, ( APP_VERSION, json.dumps({"tool": tool}, ensure_ascii=False), repository.database.now_iso(), ), )