Skip to content

Phase 7.1: AuthService facade — обернуть auth_manager.py в класс #642

@ShaerWare

Description

@ShaerWare

Parent

Sub-issue of #641 (Phase 7: Service facade migration)

Зависит от

Цель

Обернуть функции из auth_manager.py в класс AuthService, соответствующий Protocol из modules/core/protocols.py. Обновить все call sites.

Текущее состояние

auth_manager.py содержит ~15 module-level функций:

  • authenticate_user(username, password) -> Optional[User]
  • decode_token(token) -> Optional[TokenPayload]
  • create_access_token(username, role, user_id, workspace_id) -> tuple
  • create_session(...) -> LoginResponse
  • revoke_session(jti) -> bool
  • revoke_all_user_sessions(user_id) -> int
  • get_user_permissions(user) -> Dict[str, str]
  • level_gte(), user_has_level(), workspace_context()
  • require_admin(), require_permission() — FastAPI dependencies

Call sites: ~50 мест в роутерах и оркестраторе.

Что сделать

  1. Создать класс AuthService в modules/core/auth_service.py, реализующий Protocol
  2. Методы делегируют к существующим функциям (Strangler Fig)
  3. Возвраты типизированы через UserInfo, LoginResult, TokenInfo из modules/core/schemas.py
  4. Singleton auth_service = AuthService() экспортируется из модуля
  5. Постепенно мигрировать call sites с from auth_manager import X на from modules.core.auth_service import auth_service
  6. FastAPI dependencies (require_admin, require_permission) остаются функциями — они не часть Protocol

Нюансы

  • auth_manager.py остаётся как тонкий фасад (backward compat)
  • Pydantic User vs TypedDict UserInfo — нужна конвертация на границе
  • _member_role_cache — internal, не в Protocol
  • JWT секрет — config dependency, нужно решить как инжектить

Критерии готовности

  • AuthService класс реализует Protocol из modules/core/protocols.py
  • Возвраты используют TypedDict из modules/core/schemas.py
  • Call sites мигрированы (или auth_manager.py делегирует к AuthService)
  • Тесты, CI зелёный

Оценка: M (1 PR)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low priority / Backlogphase:5-techdebtPhase 5: Technical DebtrefactoringArchitectural refactoring

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions