feat(k1): stabilize LAB bridge and isolate onboard device integration
This commit is contained in:
@@ -136,3 +136,52 @@ def sensor_operation(
|
||||
return operation(fleet, vehicle_id, operation_id)
|
||||
except PairingError as error:
|
||||
raise HTTPException(404, str(error)) from None
|
||||
|
||||
|
||||
@router.get("/{vehicle_id}/devices/enrollment")
|
||||
def enrollment_state(
|
||||
vehicle_id: str, response: Response, fleet: Annotated[FleetRegistry, Depends(local_operator)]
|
||||
):
|
||||
response.headers["Cache-Control"] = "no-store"
|
||||
try:
|
||||
with fleet.lock:
|
||||
row = fleet.find(vehicle_id)
|
||||
return {
|
||||
**row.get("device_enrollment", {"available": False}),
|
||||
"node_id": row["node_id"],
|
||||
"name": row["name"],
|
||||
"fresh": fleet.public(row)["connectivity"] == "online",
|
||||
}
|
||||
except PairingError as error:
|
||||
raise HTTPException(404, str(error)) from None
|
||||
|
||||
|
||||
@router.post("/{vehicle_id}/devices/enrollment/operations")
|
||||
def enrollment_submit(
|
||||
vehicle_id: str,
|
||||
body: dict,
|
||||
response: Response,
|
||||
fleet: Annotated[FleetRegistry, Depends(local_operator)],
|
||||
):
|
||||
response.headers["Cache-Control"] = "no-store"
|
||||
try:
|
||||
return fleet.device_enrollment.submit(fleet, vehicle_id, body)
|
||||
except (PairingError, ValueError, TypeError):
|
||||
# Validation diagnostics must never echo a supplied credential.
|
||||
raise HTTPException(
|
||||
409, "Запрос подключения не принят. Обновите БК и проверьте параметры сети."
|
||||
) from None
|
||||
|
||||
|
||||
@router.get("/{vehicle_id}/devices/enrollment/operations/{operation_id}")
|
||||
def enrollment_operation(
|
||||
vehicle_id: str,
|
||||
operation_id: str,
|
||||
response: Response,
|
||||
fleet: Annotated[FleetRegistry, Depends(local_operator)],
|
||||
):
|
||||
response.headers["Cache-Control"] = "no-store"
|
||||
try:
|
||||
return fleet.device_enrollment.operation(fleet, vehicle_id, operation_id)
|
||||
except PairingError as error:
|
||||
raise HTTPException(404, str(error)) from None
|
||||
|
||||
Reference in New Issue
Block a user