mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
feat: Add API endpoint to list node files
Implement issue #2719 - Add API endpoint to list project files - Add GET /v3/projects/{project_id}/nodes/{node_id}/files endpoint - Add list_node_files() method to Project class - Add security checks to prevent path traversal - Filter out .ghost temporary files - Return file paths with MD5 checksums - Require Node.Audit privilege This allows users to discover dynamically created files such as QEMU disk images created via the disk image API. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
e0860555ba
commit
5b75d633aa
3 files changed
+69
No files matched your search
@@ -192,6 +192,20 @@ async def get_compute_project_files(project: Project = Depends(dep_project)) ->
|
||||
return await project.list_files()
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}/nodes/{node_type}/{node_id}/files", response_model=List[schemas.ProjectFile])
|
||||
async def get_compute_node_files(
|
||||
node_type: str,
|
||||
node_id: str,
|
||||
project: Project = Depends(dep_project)
|
||||
) -> List[schemas.ProjectFile]:
|
||||
"""
|
||||
Return files belonging to a specific node.
|
||||
"""
|
||||
|
||||
node_path = f"project-files/{node_type}/{node_id}"
|
||||
return await project.list_node_files(node_path)
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}/files/{file_path:path}")
|
||||
async def get_compute_project_file(file_path: str, project: Project = Depends(dep_project)) -> FileResponse:
|
||||
"""
|
||||
|
||||
@@ -522,6 +522,23 @@ async def delete_disk_image(
|
||||
await node.delete(f"/disk_image/{disk_name}")
|
||||
|
||||
|
||||
@router.get("/{node_id}/files", response_model=List[schemas.ProjectFile], dependencies=[Depends(has_privilege("Node.Audit"))])
|
||||
async def list_node_files(node: Node = Depends(dep_node)) -> List[schemas.ProjectFile]:
|
||||
"""
|
||||
List files in a node directory.
|
||||
|
||||
Required privilege: Node.Audit
|
||||
"""
|
||||
|
||||
node_type = node.node_type
|
||||
res = await node.compute.http_query(
|
||||
"GET",
|
||||
f"/projects/{node.project.id}/nodes/{node_type}/{node.id}/files",
|
||||
timeout=None
|
||||
)
|
||||
return res.json
|
||||
|
||||
|
||||
@router.get("/{node_id}/files/{file_path:path}", dependencies=[Depends(has_privilege("Node.Audit"))])
|
||||
async def get_file(file_path: str, node: Node = Depends(dep_node)) -> Response:
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user