Files
Juan Denis 2f52c87a39 Add /ports/check and /ports/suggest
The deploy paths already know which host ports are taken (app rows,
slot rows, Docker mappings, a bind test) but only used that to pick a
port silently. Exposing it lets the shared port input say "8001 is
used by shop-api" and offer the next free port, instead of failing
at deploy time.
2026-10-03 22:46:54 -04:00

26 lines
822 B
Python

"""Host-port checks for the panel's port inputs. Mounted at ``/api/v1/ports``.
GET /check?port=<n> — valid / free / privileged, and who holds it
GET /suggest?start=<n> — the next free port at or above ``start``
Read-only. Developer role, the same as deploying the app that would use it.
"""
from flask import Blueprint, jsonify, request
from app.middleware.rbac import developer_required
from app.services import port_service
ports_bp = Blueprint('ports', __name__)
@ports_bp.route('/check', methods=['GET'])
@developer_required
def check_port():
return jsonify(port_service.check_port(request.args.get('port'))), 200
@ports_bp.route('/suggest', methods=['GET'])
@developer_required
def suggest_port():
return jsonify({'port': port_service.suggest_port(request.args.get('start', 8000))}), 200