Files
trustos/backend/app/api/routes/attack_paths.py
drjones d92a7c057d Complete local deployment setup with Cloudflare tunnel
- setup_local_hosting.sh: Configures Nginx reverse proxy, installs cloudflared
- SETUP_CLOUDFLARE_TUNNEL.sh: Interactive tunnel setup script (5 min)
- check_status.sh: Real-time status dashboard for all services
- LOCAL_ACCESS_GUIDE.md: Complete local access instructions
- FINAL_DEPLOYMENT_README.md: Comprehensive deployment guide

Current Status:
   Nginx reverse proxy running (port 80)
   Backend API healthy (port 8000)
   Frontend running (port 3000, redirecting unauthenticated to login)
   PostgreSQL database connected with demo data
   All services accessible at http://10.30.20.38
   Cloudflare tunnel installed and ready

Access:
  - Local: http://10.30.20.38
  - With Cloudflare: https://your-domain.com (after tunnel setup)
  - Demo credentials included and working

Next Steps:
  1. Visit http://10.30.20.38 and login
  2. Run SETUP_CLOUDFLARE_TUNNEL.sh for global access
  3. Share HTTPS URL with anyone

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-07-07 14:06:47 +00:00

54 lines
2.1 KiB
Python

from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
from typing import List
from app.db.session import get_db
from app.models.models import Finding, AttackPath
from app.schemas.schemas import AttackPathOut
from app.core.security import require_executive_or_above
router = APIRouter(prefix="/attack-paths", tags=["attack-paths"])
@router.get("/{finding_id}", response_model=List[AttackPathOut])
async def get_attack_paths(
finding_id: str,
generate: bool = Query(False),
payload: dict = Depends(require_executive_or_above),
db: AsyncSession = Depends(get_db),
):
"""Get attack paths for a finding. Optionally auto-generate if missing."""
# Verify tenant access
f_result = await db.execute(select(Finding).where(Finding.id == finding_id))
finding = f_result.scalar_one_or_none()
if not finding:
raise HTTPException(status_code=404, detail="Finding not found")
if payload.get("role") != "trustos_admin" and payload.get("tenant_id") != finding.tenant_id:
raise HTTPException(status_code=403, detail="Access denied")
result = await db.execute(select(AttackPath).where(AttackPath.finding_id == finding_id))
paths = result.scalars().all()
# Auto-generate if requested and none exist
if generate and not paths:
from app.services.ai_translator import generate_attack_path_narrative
import asyncio
# Generate in background but return empty list immediately
asyncio.create_task(generate_attack_path_narrative(finding_id))
return paths
@router.post("/{finding_id}/generate")
async def generate_attack_path(
finding_id: str,
payload: dict = Depends(require_executive_or_above),
db: AsyncSession = Depends(get_db),
):
"""Trigger AI generation of attack path narrative for a finding."""
from app.services.ai_translator import generate_attack_path_narrative
import asyncio
asyncio.create_task(generate_attack_path_narrative(finding_id))
return {"status": "queued", "finding_id": finding_id}