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

66 lines
2.5 KiB
Python

"""DNS provider connections (Cloudflare, Route 53, DigitalOcean, GoDaddy).
These routes back the Settings -> Connections DNS tiles and the wildcard-TLS
flows, so they are core — a panel without the serverkit-email extension must
still be able to connect a DNS provider. They keep the historical
/api/v1/email/dns-providers paths (the routes originally lived in the email
API before the extraction) so existing frontends keep working.
"""
from flask import Blueprint, jsonify
from app.middleware.rbac import admin_required, viewer_required
from app.services.dns_provider_service import DNSProviderService
from app.api._request import json_object
dns_providers_bp = Blueprint('dns_providers', __name__)
@dns_providers_bp.route('/dns-providers', methods=['GET'])
@viewer_required
def list_dns_providers():
"""List configured DNS providers."""
providers = DNSProviderService.list_providers()
return jsonify({'providers': providers}), 200
@dns_providers_bp.route('/dns-providers', methods=['POST'])
@admin_required
def add_dns_provider():
"""Add a DNS provider."""
data = json_object()
if not data or not data.get('name') or not data.get('provider') or not data.get('api_key'):
return jsonify({'success': False, 'error': 'Name, provider, and api_key are required'}), 400
result = DNSProviderService.add_provider(
name=data['name'],
provider=data['provider'],
api_key=data['api_key'],
api_secret=data.get('api_secret'),
api_email=data.get('api_email'),
is_default=data.get('is_default', False),
)
return jsonify(result), 201 if result.get('success') else 400
@dns_providers_bp.route('/dns-providers/<int:provider_id>', methods=['DELETE'])
@admin_required
def remove_dns_provider(provider_id):
"""Remove a DNS provider."""
result = DNSProviderService.remove_provider(provider_id)
return jsonify(result), 200 if result.get('success') else 400
@dns_providers_bp.route('/dns-providers/<int:provider_id>/test', methods=['POST'])
@admin_required
def test_dns_provider(provider_id):
"""Test DNS provider connection."""
result = DNSProviderService.test_connection(provider_id)
return jsonify(result), 200 if result.get('success') else 400
@dns_providers_bp.route('/dns-providers/<int:provider_id>/zones', methods=['GET'])
@viewer_required
def list_dns_zones(provider_id):
"""List DNS zones from a provider."""
result = DNSProviderService.list_zones(provider_id)
return jsonify(result), 200 if result.get('success') else 400