Serialise agent enrollment and guard heartbeat auth context

This commit is contained in:
2025-10-18 00:03:13 -06:00
parent 7b0e2f48e1
commit 91e7a6de88
2 changed files with 38 additions and 8 deletions

View File

@@ -28,10 +28,18 @@ def register(
except Exception:
return None
def _auth_context():
ctx = getattr(g, "device_auth", None)
if ctx is None:
log("server", f"device auth context missing for {request.path}")
return ctx
@blueprint.route("/api/agent/heartbeat", methods=["POST"])
@require_device_auth(auth_manager)
def heartbeat():
ctx = getattr(g, "device_auth")
ctx = _auth_context()
if ctx is None:
return jsonify({"error": "auth_context_missing"}), 500
payload = request.get_json(force=True, silent=True) or {}
now_ts = int(time.time())
@@ -90,7 +98,9 @@ def register(
@blueprint.route("/api/agent/script/request", methods=["POST"])
@require_device_auth(auth_manager)
def script_request():
ctx = getattr(g, "device_auth")
ctx = _auth_context()
if ctx is None:
return jsonify({"error": "auth_context_missing"}), 500
if ctx.status != "active":
return jsonify(
{