| 1 | from fastapi import APIRouter |
| 2 | from fastapi import Security |
| 3 | from loguru import logger |
| 4 | |
| 5 | from app.auth.routes.auth import AuthHandler |
| 6 | from app.integrations.nuclei.schema.nuclei import DeleteNucleiReportResponse |
| 7 | from app.integrations.nuclei.schema.nuclei import NucleiReportCollectionResponse |
| 8 | from app.integrations.nuclei.schema.nuclei import NucleiReportsAvailableResponse |
| 9 | from app.integrations.nuclei.schema.nuclei import NucleiScanRequest |
| 10 | from app.integrations.nuclei.schema.nuclei import NucleiScanResponse |
| 11 | from app.integrations.nuclei.services.nuclei import delete_nuclei_report |
| 12 | from app.integrations.nuclei.services.nuclei import get_nuclei_report |
| 13 | from app.integrations.nuclei.services.nuclei import get_nuclei_reports_available |
| 14 | from app.integrations.nuclei.services.nuclei import post_to_copilot_nuclei_module |
| 15 | |
| 16 | integration_nuclei_router = APIRouter() |
| 17 | |
| 18 | |
| 19 | @integration_nuclei_router.get( |
| 20 | "/all_reports", |
| 21 | response_model=NucleiReportsAvailableResponse, |
| 22 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 23 | ) |
| 24 | async def get_all_reports(): |
| 25 | logger.info("Collecting Nuclei Reports") |
| 26 | return await get_nuclei_reports_available() |
| 27 | |
| 28 | |
| 29 | @integration_nuclei_router.get( |
| 30 | "/report/{host}/{report}", |
| 31 | response_model=NucleiReportCollectionResponse, |
| 32 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 33 | ) |
| 34 | async def get_report(host: str, report: str = "index.md"): |
| 35 | logger.info(f"Getting Nuclei Report for {host} and {report}") |
| 36 | return await get_nuclei_report(host, report) |
| 37 | |
| 38 | |
| 39 | @integration_nuclei_router.post( |
| 40 | "/scan", |
| 41 | response_model=NucleiScanResponse, |
| 42 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 43 | ) |
| 44 | async def post_test( |
| 45 | request: NucleiScanRequest, |
| 46 | ): |
| 47 | logger.info(f"Running Nuclei Scan for {request.host}") |
| 48 | return await post_to_copilot_nuclei_module(request) |
| 49 | |
| 50 | |
| 51 | @integration_nuclei_router.delete( |
| 52 | "/delete_report/{host}", |
| 53 | response_model=DeleteNucleiReportResponse, |
| 54 | dependencies=[Security(AuthHandler().require_any_scope("admin", "analyst"))], |
| 55 | ) |
| 56 | async def delete_report(host: str): |
| 57 | logger.info(f"Deleting Nuclei Report for {host}") |
| 58 | return await delete_nuclei_report(host) |