Skip to content

Latest commit

 

History

History
218 lines (172 loc) · 5.7 KB

File metadata and controls

218 lines (172 loc) · 5.7 KB

API Modularisierung - Master Plan

Ziel: Reduziere api/main.py von 3.800 auf <500 Zeilen Status: V1 Routes etabliert, Migration läuft


📊 Aktueller Status

Legacy Endpoints in api/main.py (48 Endpoints)

Bereich Endpoints Status
Auth 7 (/auth/*) ⚠️ Migration pending
Scans 6 (/scans/*) ⚠️ Migration pending
Findings 2 (/findings/*) ⚠️ Migration pending
Tools 2 (/tools/*) ⚠️ Migration pending
Reports 3 (/reports/*) ⚠️ Migration pending
WebSocket 5 (/ws/*) ⚠️ Migration pending
Health 2 (/health, /info) ⚠️ Migration pending
Sonstige 21 ⚠️ Migration pending

V1 Routes (48 Endpoints bereits migriert)

api/routes/v1/
├── auth.py         (6 endpoints) ✅
├── scans.py        (7 endpoints) ✅
├── findings.py     (4 endpoints) ✅
├── tools.py        (2 endpoints) ✅
├── reports.py      (3 endpoints) ✅
├── schedules.py    (6 endpoints) ✅
├── settings.py     (6 endpoints) ✅
├── stats.py        (4 endpoints) ✅
├── notifications.py (3 endpoints) ✅
├── health.py       (2 endpoints) ✅
├── metrics.py      (1 endpoints) ✅
└── websocket.py    (4 endpoints) ✅

🎯 Migrations-Strategie

Phase 1: Auth Endpoints (Priorität: Hoch)

Endpoints: 7 Aufwand: 2h

# Zu migrieren:
POST /auth/loginapi/routes/v1/auth.py (existiert)
GET /auth/meapi/routes/v1/auth.py (existiert)
POST /auth/refreshapi/routes/v1/auth.py (existiert)
GET /csrf-tokenapi/routes/v1/auth.py (existiert)
POST /auth/logoutapi/routes/v1/auth.py (existiert)
POST /auth/logout-allapi/routes/v1/auth.py (existiert)

Aktion:

  1. Prüfe ob V1 Endpoints funktional identisch sind
  2. Füge Deprecation-Warnungen zu Legacy Endpoints hinzu
  3. Aktualisiere Tests

Phase 2: Scan Endpoints (Priorität: Hoch)

Endpoints: 6 Aufwand: 3h

# Zu migrieren:
POST /scansapi/routes/v1/scans.py (existiert)
GET /scansapi/routes/v1/scans.py (existiert)
GET /scans/{id}                → api/routes/v1/scans.py (existiert)
PATCH /scans/{id}              → api/routes/v1/scans.py (existiert)
DELETE /scans/{id}             → api/routes/v1/scans.py (existiert)
GET /scans/{id}/findingsapi/routes/v1/scans.py (existiert)

Phase 3: Finding Endpoints (Priorität: Mittel)

Endpoints: 2 Aufwand: 1h

# Zu migrieren:
POST /scans/{id}/findingsapi/routes/v1/findings.py (existiert)
PATCH /findings/{id}           → api/routes/v1/findings.py (existiert)

Phase 4: Tool Endpoints (Priorität: Mittel)

Endpoints: 2 Aufwand: 1h

# Zu migrieren:
POST /tools/executeapi/routes/v1/tools.py (existiert)
GET /toolsapi/routes/v1/tools.py (existiert)

Phase 5: Report Endpoints (Priorität: Mittel)

Endpoints: 3 Aufwand: 1h

# Zu migrieren:
POST /reportsapi/routes/v1/reports.py (existiert)
GET /reportsapi/routes/v1/reports.py (existiert)
GET /reports/{id}/downloadapi/routes/v1/reports.py (existiert)

Phase 6: WebSocket Endpoints (Priorität: Niedrig)

Endpoints: 5 Aufwand: 2h

# Zu migrieren:
/ws/scans/{id}
/ws/notifications
/ws/{client_id}
/agents/ws

🔧 Implementierungs-Plan

Schritt 1: V1 Endpoints vervollständigen

# Auth
# - Prüfe: Login, Logout, Refresh, Me, CSRF
# - Füge fehlende hinzu: logout-all

# Scans
# - Prüfe: CRUD + Findings

# Tools
# - Prüfe: List + Execute

# Reports
# - Prüfe: CRUD + Download

Schritt 2: Deprecation Strategy

# In api/main.py für jeden Legacy Endpoint:

@app.post("/auth/login", deprecated=True)
async def login(...):
    """
    ⚠️ DEPRECATED: Use POST /api/v1/auth/login instead

    Dieser Endpoint wird in v2.0 entfernt.
    Migration Guide: docs/MIGRATION_v1.md
    """
    # Redirect to v1 implementation
    from api.routes.v1.auth import login as v1_login
    return await v1_login(...)

Schritt 3: Tests migrieren

# Tests für Legacy Endpoints
mv tests/test_legacy_auth.py tests/api/v1/test_auth.py

# Neue Tests für V1 Endpoints
pytest tests/api/v1/ -v

📋 Konkrete TODOs

Heute (2-3h)

  • Auth Endpoints: Vergleiche Legacy vs V1
  • Auth Endpoints: Füge logout-all zu V1 hinzu
  • Auth Endpoints: Markiere Legacy als deprecated
  • Scans Endpoints: Vergleiche Implementierungen
  • Scans Endpoints: Markiere Legacy als deprecated

Diese Woche (8-10h)

  • Tools Endpoints migrieren
  • Findings Endpoints migrieren
  • Reports Endpoints migrieren
  • Health Endpoints migrieren
  • Tests für alle V1 Endpoints

Nächste Woche (6-8h)

  • WebSocket Endpoints migrieren
  • Legacy Endpoints entfernen
  • api/main.py bereinigen (<500 Zeilen)
  • Dokumentation aktualisieren

🎯 Erfolgskriterien

  1. api/main.py < 500 Zeilen
  2. Alle Endpoints unter /api/v1/
  3. Legacy Endpoints mit Deprecation-Warnungen
  4. 100% Test-Abdeckung für V1
  5. Keine Breaking Changes

📊 Fortschritt

Auth:     [████░░░░░░] 40%
Scans:    [████░░░░░░] 40%
Findings: [░░░░░░░░░░] 0%
Tools:    [░░░░░░░░░░] 0%
Reports:  [░░░░░░░░░░] 0%
WebSocket:[░░░░░░░░░░] 0%
--------------------------------
Gesamt:   [██░░░░░░░░] 15%

Nächster Schritt: Auth Endpoints vergleichen und Deprecation hinzufügen