refactor(admin): extract _check_token into shared AdminTokenAuth dep #133
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#133
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "refactor/admin-token-dependency-128"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Per audit batch #127 P2 hygiene: identical `_check_token` в 3 admin файлах. Extract в shared FastAPI dependency.
Change
New: `backend/app/core/deps.py`
```python
def verify_admin_token(x_admin_token: Annotated[str | None, Header(...)] = None) -> None:
# 503 if env missing, 401 if mismatch
...
AdminTokenAuth = Annotated[None, Depends(verify_admin_token)]
```
Replaced in 27 endpoints
Removed local `_check_token` defs + cleaned unused imports.
Semantics preserved
Все 3 original — identical (503 + 401, same header, same env). Only change: unified 503 detail text (cosmetic — клиент не парсит detail).
Checks
Vault
`code/patterns/Pattern_Admin_Token_Dependency_May14.md`
Closes #128
Refs: #127
Bot review (SHA
f8023a1, CI ✅)Чистый refactor: identical
_check_tokenв 3 файлах → shared FastAPI dependency. Анализ:✅ Pattern
Annotated[None, Depends(...)]— идиоматический FastAPI 0.95+; типовой aliasAdminTokenAuthудобно переиспользуется в 27 endpoints✅ Сохранены 503/401 семантика + header alias
X-Admin-Token— клиенты не сломаются✅ Удалены локальные
_check_token+ cleaned unused imports (Headerубран где больше не нужен,HTTPExceptionоставлен где используется для других целей)✅ Pre-existing
HTTPExceptionдляobjective_api_keyвadmin_scrape.py:543— оставлен, не связан с token check✅ 64/64 admin tests passing per PR body; CI green
Минор (НЕ блокер — fix в follow-up или ignore)
Грамматическая опечатка в docstring
trigger_objective_sync_our(admin_scrape.py):После «расширить за» правильный падеж — пределы (винительный), не пределов (родительный). Косметика, видимо случайно затронуто во время refactor'а. Cosmetic-only, не влияет на runtime.
approve merge