Форматирование всего серверного кода по стандартам (black)

This commit is contained in:
parent e61ffd793c
commit 06a5a758a3
28 changed files with 611 additions and 305 deletions

View file

@ -7,9 +7,11 @@ from services.ufw_service import UFWService
router = APIRouter()
class RuleNumbers(BaseModel):
numbers: List[int] = Field(..., description="Список номеров правил для удаления")
@router.get("/rules", response_model=UFWRulesResponse)
async def get_ufw_rules():
"""
@ -21,6 +23,7 @@ async def get_ufw_rules():
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error: {str(e)}")
@router.get("/status", response_model=UFWStatus)
async def get_ufw_status():
"""
@ -32,6 +35,7 @@ async def get_ufw_status():
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error: {str(e)}")
@router.post("/enable")
async def enable_ufw():
"""
@ -47,6 +51,7 @@ async def enable_ufw():
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error: {str(e)}")
@router.post("/disable")
async def disable_ufw():
"""
@ -62,6 +67,7 @@ async def disable_ufw():
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error: {str(e)}")
@router.post("/rules/in")
async def add_ufw_in_rules(rules: List[UFWRule]):
"""
@ -74,9 +80,9 @@ async def add_ufw_in_rules(rules: List[UFWRule]):
if not status.enabled:
raise HTTPException(
status_code=400,
detail="UFW отключен. Включите UFW перед добавлением правил."
detail="UFW отключен. Включите UFW перед добавлением правил.",
)
result = ufw_service.add_rules(rules)
if result["success"]:
successful_rules = len([r for r in result["results"] if r["success"]])
@ -84,13 +90,17 @@ async def add_ufw_in_rules(rules: List[UFWRule]):
return {
"status": "success",
"message": f"Добавлено {successful_rules} из {total_rules} правил",
"details": result
"details": result,
}
else:
raise HTTPException(status_code=500, detail=result.get("error", "Не удалось добавить правила"))
raise HTTPException(
status_code=500,
detail=result.get("error", "Не удалось добавить правила"),
)
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error: {str(e)}")
@router.post("/rules/out")
async def add_ufw_out_rules(rules: List[UFWRule]):
"""
@ -103,17 +113,23 @@ async def add_ufw_out_rules(rules: List[UFWRule]):
if not status.enabled:
raise HTTPException(
status_code=400,
detail="UFW отключен. Включите UFW перед добавлением правил."
detail="UFW отключен. Включите UFW перед добавлением правил.",
)
success = ufw_service.add_ufw_out_rules(rules)
if success:
return {"status": "success", "message": "Исходящие правила UFW успешно добавлены"}
return {
"status": "success",
"message": "Исходящие правила UFW успешно добавлены",
}
else:
raise HTTPException(status_code=500, detail="Не удалось добавить исходящие правила UFW")
raise HTTPException(
status_code=500, detail="Не удалось добавить исходящие правила UFW"
)
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error: {str(e)}")
@router.delete("/rules")
async def delete_ufw_rules(rule_numbers: RuleNumbers):
"""
@ -126,7 +142,7 @@ async def delete_ufw_rules(rule_numbers: RuleNumbers):
return {
"status": "success",
"message": f"Удалено {result['successful']} из {result['total']} правил",
"details": result
"details": result,
}
else:
raise HTTPException(status_code=500, detail=result["error"])