mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-10-26 22:01:59 -06:00
Restore agent detail ingestion and device description updates
This commit is contained in:
@@ -11,7 +11,10 @@ from flask import Blueprint, Flask, current_app, g, jsonify, request
|
||||
from Data.Engine.builders.device_auth import DeviceAuthRequestBuilder
|
||||
from Data.Engine.domain.device_auth import DeviceAuthContext, DeviceAuthFailure
|
||||
from Data.Engine.services.container import EngineServiceContainer
|
||||
from Data.Engine.services.devices.device_inventory_service import DeviceHeartbeatError
|
||||
from Data.Engine.services.devices.device_inventory_service import (
|
||||
DeviceDetailsError,
|
||||
DeviceHeartbeatError,
|
||||
)
|
||||
|
||||
AGENT_CONTEXT_HEADER = "X-Borealis-Agent-Context"
|
||||
|
||||
@@ -110,4 +113,36 @@ def script_request() -> Any:
|
||||
return jsonify(response)
|
||||
|
||||
|
||||
__all__ = ["register", "blueprint", "heartbeat", "script_request", "require_device_auth"]
|
||||
@blueprint.route("/api/agent/details", methods=["POST"])
|
||||
@require_device_auth
|
||||
def save_details() -> Any:
|
||||
services = _services()
|
||||
payload = request.get_json(force=True, silent=True) or {}
|
||||
context = cast(DeviceAuthContext, g.device_auth)
|
||||
|
||||
try:
|
||||
services.device_inventory.save_agent_details(context=context, payload=payload)
|
||||
except DeviceDetailsError as exc:
|
||||
error_payload = {"error": exc.code}
|
||||
if exc.code == "invalid_payload":
|
||||
return jsonify(error_payload), 400
|
||||
if exc.code in {"fingerprint_mismatch", "guid_mismatch"}:
|
||||
return jsonify(error_payload), 403
|
||||
if exc.code == "device_not_registered":
|
||||
return jsonify(error_payload), 404
|
||||
current_app.logger.exception(
|
||||
"device-details-error guid=%s code=%s", context.identity.guid.value, exc.code
|
||||
)
|
||||
return jsonify(error_payload), 500
|
||||
|
||||
return jsonify({"status": "ok"})
|
||||
|
||||
|
||||
__all__ = [
|
||||
"register",
|
||||
"blueprint",
|
||||
"heartbeat",
|
||||
"script_request",
|
||||
"save_details",
|
||||
"require_device_auth",
|
||||
]
|
||||
|
||||
@@ -5,7 +5,7 @@ from ipaddress import ip_address
|
||||
from flask import Blueprint, Flask, current_app, jsonify, request, session
|
||||
|
||||
from Data.Engine.services.container import EngineServiceContainer
|
||||
from Data.Engine.services.devices import RemoteDeviceError
|
||||
from Data.Engine.services.devices import DeviceDescriptionError, RemoteDeviceError
|
||||
|
||||
blueprint = Blueprint("engine_devices", __name__)
|
||||
|
||||
@@ -64,6 +64,24 @@ def get_device_by_guid(guid: str) -> object:
|
||||
return jsonify(device)
|
||||
|
||||
|
||||
@blueprint.route("/api/device/description/<hostname>", methods=["POST"])
|
||||
def set_device_description(hostname: str) -> object:
|
||||
payload = request.get_json(silent=True) or {}
|
||||
description = payload.get("description")
|
||||
try:
|
||||
_inventory().update_device_description(hostname, description)
|
||||
except DeviceDescriptionError as exc:
|
||||
if exc.code == "invalid_hostname":
|
||||
return jsonify({"error": "invalid hostname"}), 400
|
||||
if exc.code == "not_found":
|
||||
return jsonify({"error": "not found"}), 404
|
||||
current_app.logger.exception(
|
||||
"device-description-error host=%s code=%s", hostname, exc.code
|
||||
)
|
||||
return jsonify({"error": "internal error"}), 500
|
||||
return jsonify({"status": "ok"})
|
||||
|
||||
|
||||
@blueprint.route("/api/agent_devices", methods=["GET"])
|
||||
def list_agent_devices() -> object:
|
||||
guard = _require_admin()
|
||||
|
||||
Reference in New Issue
Block a user