Files
Juan Denis 55d8fb1e44 Read route bodies through json_object()
328 more routes used a JSON body as a dict straight from
request.get_json(), so a body of null, [] or a bare string crashed them
into a 500. Bare reads become json_object(); the
'get_json(silent=True) or {}' reads of action routes become
json_object(optional=True), which still treats a missing body as {}.
Routes that take arrays or pass the body through untouched are left
alone. The full backend suite shows no new failures.

Also carries three files' bare section citations (apps, backups,
notifications) and the extended citation guard, which needed them.
2026-10-10 20:53:43 -04:00

45 lines
1.5 KiB
Python

"""Linked-panel API — manage this panel's link to a master ServerKit panel."""
from flask import Blueprint, jsonify
from flask_jwt_extended import jwt_required
from app.middleware.rbac import developer_required
from app.services.linked_panel_service import LinkedPanelService
from app.api._request import json_object
linked_panel_bp = Blueprint('linked_panel', __name__)
@linked_panel_bp.route('', methods=['GET'])
@jwt_required()
def get_status():
"""Current link status (linked/connected/last_error)."""
return jsonify(LinkedPanelService.get_status())
@linked_panel_bp.route('', methods=['POST'])
@developer_required
def link():
"""Link this panel to a master ServerKit panel.
Body: {"master_url": "https://panel-a", "registration_token": "sk_reg_…",
"name": "optional display name"}
The registration token comes from the master's Servers page (Add Server
/ regenerate-token) — the same token the Go agent consumes.
"""
data = json_object(optional=True)
result = LinkedPanelService.link(
master_url=data.get('master_url'),
registration_token=data.get('registration_token'),
name=data.get('name'),
)
if not result.get('success'):
return jsonify(result), 400
return jsonify(result)
@linked_panel_bp.route('', methods=['DELETE'])
@developer_required
def unlink():
"""Stop the embedded agent and forget the master credentials."""
return jsonify(LinkedPanelService.unlink())