Return 405 error for unsupported actions for other node types

This commit is contained in:
grossmj committed 2026-03-15 22:38:51 +08:00
1 parent 0056bdd19b
commit 6e7738a14f
13 files changed
+198 -63

No files matched your search

+42 -12
View File
@@ -22,7 +22,7 @@ import aiohttp
import asyncio
import ipaddress
from fastapi import APIRouter, Depends, WebSocket, WebSocketDisconnect, Request, Response, status, Query
from fastapi import APIRouter, Depends, WebSocket, WebSocketDisconnect, Request, Response, status, Query, HTTPException
from fastapi.encoders import jsonable_encoder
from fastapi.routing import APIRoute
from typing import List, Callable, Optional
@@ -179,7 +179,11 @@ async def start_all_nodes(project: Project = Depends(dep_project)) -> None:
Required privilege: Node.PowerMgmt
"""
await project.start_all()
try:
await project.start_all()
except HTTPException as e:
if not e.status_code == status.HTTP_405_METHOD_NOT_ALLOWED:
raise
@router.post("/stop", status_code=status.HTTP_204_NO_CONTENT, dependencies=[Depends(has_privilege("Node.PowerMgmt"))])
@@ -190,7 +194,11 @@ async def stop_all_nodes(project: Project = Depends(dep_project)) -> None:
Required privilege: Node.PowerMgmt
"""
await project.stop_all()
try:
await project.stop_all()
except HTTPException as e:
if not e.status_code == status.HTTP_405_METHOD_NOT_ALLOWED:
raise
@router.post("/suspend", status_code=status.HTTP_204_NO_CONTENT, dependencies=[Depends(has_privilege("Node.PowerMgmt"))])
@@ -201,7 +209,11 @@ async def suspend_all_nodes(project: Project = Depends(dep_project)) -> None:
Required privilege: Node.PowerMgmt
"""
await project.suspend_all()
try:
await project.suspend_all()
except HTTPException as e:
if not e.status_code == status.HTTP_405_METHOD_NOT_ALLOWED:
raise
@router.post("/reload", status_code=status.HTTP_204_NO_CONTENT, dependencies=[Depends(has_privilege("Node.PowerMgmt"))])
@@ -212,8 +224,12 @@ async def reload_all_nodes(project: Project = Depends(dep_project)) -> None:
Required privilege: Node.PowerMgmt
"""
await project.stop_all()
await project.start_all()
try:
await project.stop_all()
await project.start_all()
except HTTPException as e:
if not e.status_code == status.HTTP_405_METHOD_NOT_ALLOWED:
raise
@router.get("/{node_id}", response_model=schemas.Node, dependencies=[Depends(has_privilege("Node.Audit"))])
@@ -300,8 +316,11 @@ async def start_node(start_data: dict, node: Node = Depends(dep_node)) -> None:
Required privilege: Node.PowerMgmt
"""
await node.start(data=start_data)
try:
await node.start(data=start_data)
except HTTPException as e:
if not e.status_code == status.HTTP_405_METHOD_NOT_ALLOWED:
raise
@router.post(
"/{node_id}/stop",
@@ -315,7 +334,11 @@ async def stop_node(node: Node = Depends(dep_node)) -> None:
Required privilege: Node.PowerMgmt
"""
await node.stop()
try:
await node.stop()
except HTTPException as e:
if not e.status_code == status.HTTP_405_METHOD_NOT_ALLOWED:
raise
@router.post(
@@ -330,7 +353,11 @@ async def suspend_node(node: Node = Depends(dep_node)) -> None:
Required privilege: Node.PowerMgmt
"""
await node.suspend()
try:
await node.suspend()
except HTTPException as e:
if not e.status_code == status.HTTP_405_METHOD_NOT_ALLOWED:
raise
@router.post(
@@ -345,8 +372,11 @@ async def reload_node(node: Node = Depends(dep_node)) -> None:
Required privilege: Node.PowerMgmt
"""
await node.reload()
try:
await node.reload()
except HTTPException as e:
if not e.status_code == status.HTTP_405_METHOD_NOT_ALLOWED:
raise
@router.post(
"/{node_id}/isolate",