Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Read 40 more route bodies through json_object()

Juan Denis99a19c2fb706
diff --git a/backend/app/api/agent_plugins.py b/backend/app/api/agent_plugins.py
index c0cd231b..fca88a59 100644
--- a/backend/app/api/agent_plugins.py
+++ b/backend/app/api/agent_plugins.py
@@ -33,7 +33,7 @@ def create_plugin():
if not user or not user.is_admin:
return jsonify({'error': 'Admin access required'}), 403
- data = request.get_json()
+ data = json_object()
if not data:
return jsonify({'error': 'Request body required'}), 400
@@ -63,7 +63,7 @@ def update_plugin(plugin_id):
if not user or not user.is_admin:
return jsonify({'error': 'Admin access required'}), 403
- data = request.get_json()
+ data = json_object()
plugin = AgentPluginService.update_plugin(plugin_id, data)
if not plugin:
return jsonify({'error': 'Plugin not found'}), 404
@@ -97,7 +97,7 @@ def delete_plugin(plugin_id):
@agent_plugins_bp.route('/validate', methods=['POST'])
@jwt_required()
def validate_manifest():
- data = request.get_json()
+ data = json_object()
if not data:
return jsonify({'error': 'Manifest data required'}), 400
errors = AgentPluginService.validate_manifest(data)
diff --git a/backend/app/api/apps.py b/backend/app/api/apps.py
index 320d132f..369a9adb 100644
--- a/backend/app/api/apps.py
+++ b/backend/app/api/apps.py
@@ -441,7 +441,7 @@ def set_app_workspace(app_id):
if not user.is_admin and app.user_id != user.id:
raise permission_denied()
- target = (request.get_json() or {}).get('workspace_id')
+ target = json_object().get('workspace_id')
if target in (None, '', 'default'):
ws_id = WorkspaceService.ensure_default_workspace().id
else:
@@ -2218,7 +2218,7 @@ def update_app_backup_policy(app_id):
app = require_app(app_id, write=True)
policy = BackupPolicyService.get_or_create_policy('application', app_id)
try:
- BackupPolicyService.update_policy(policy, request.get_json() or {})
+ BackupPolicyService.update_policy(policy, json_object())
except BackupPolicyError as e:
return jsonify({'error': str(e)}), 400
return jsonify(BackupPolicyService.serialize_policy_view(policy))
@@ -2253,7 +2253,7 @@ def restore_app_backup(app_id, run_id):
app = require_app(app_id, write=True)
policy = BackupPolicyService.get_or_create_policy('application', app_id)
try:
- job = BackupPolicyService.request_restore(policy, run_id, request.get_json() or {})
+ job = BackupPolicyService.request_restore(policy, run_id, json_object())
except BackupPolicyError as e:
return jsonify({'error': str(e)}), 400
return jsonify({'success': True, 'job_id': job.id}), 202
diff --git a/backend/app/api/backups.py b/backend/app/api/backups.py
index f19097a9..609304a4 100644
--- a/backend/app/api/backups.py
+++ b/backend/app/api/backups.py
@@ -217,7 +217,7 @@ def restore_target_run(target_type, target_id, run_id):
try:
BackupPolicyService.validate_target_type(target_type)
policy = BackupPolicyService.get_or_create_policy(target_type, target_id)
- job = BackupPolicyService.request_restore(policy, run_id, request.get_json() or {})
+ job = BackupPolicyService.request_restore(policy, run_id, json_object())
except BackupPolicyError as e:
return jsonify({'error': str(e)}), 400
return jsonify({'success': True, 'job_id': job.id}), 202
@@ -259,7 +259,7 @@ def get_config():
@admin_required
def update_config():
"""Update backup configuration."""
- data = request.get_json()
+ data = json_object()
if not data:
return jsonify({'error': 'No data provided'}), 400
@@ -511,7 +511,7 @@ def add_schedule():
@admin_required
def update_schedule(schedule_id):
"""Update a backup schedule."""
- data = request.get_json()
+ data = json_object()
if not data:
return jsonify({'error': 'No data provided'}), 400
@@ -548,7 +548,7 @@ def get_storage_config():
@admin_required
def update_storage_config():
"""Update storage provider configuration."""
- data = request.get_json()
+ data = json_object()
if not data:
return jsonify({'error': 'No data provided'}), 400
diff --git a/backend/app/api/connections.py b/backend/app/api/connections.py
index 312d2038..19d65f25 100644
--- a/backend/app/api/connections.py
+++ b/backend/app/api/connections.py
@@ -110,7 +110,7 @@ def list_provider_schemas():
@admin_required
def validate_provider_credentials(kind):
result = ConnectionProviderRegistry.execute(
- kind, 'validate', payload=request.get_json() or {},
+ kind, 'validate', payload=json_object(),
partial=request.args.get('partial', '').lower() == 'true')
return _provider_response(result)
@@ -145,7 +145,7 @@ def provider_test(kind, connection_id):
def provider_rotate(kind, connection_id):
result = ConnectionProviderRegistry.execute(
kind, 'rotate', ref=_connection_ref(kind, connection_id),
- payload=request.get_json() or {})
+ payload=json_object())
_audit_provider_operation(kind, connection_id, 'rotate', result)
return _provider_response(result)
diff --git a/backend/app/api/databases.py b/backend/app/api/databases.py
index a17761e3..86f8b1ca 100644
--- a/backend/app/api/databases.py
+++ b/backend/app/api/databases.py
@@ -993,7 +993,7 @@ def docker_db_insights(container):
@admin_required
def enable_pg_stat_statements(container):
from app.services.db_config_tuner_service import DbConfigTunerService
- data = request.get_json(silent=True) or {}
+ data = json_object(optional=True)
target = _docker_db_target(container, dict(data, type='postgresql'))
return jsonify(DbConfigTunerService.enable_pg_stat_statements(target)), 200
diff --git a/backend/app/api/db_tuner.py b/backend/app/api/db_tuner.py
index 1dbfbbe8..6c7090e3 100644
--- a/backend/app/api/db_tuner.py
+++ b/backend/app/api/db_tuner.py
@@ -86,7 +86,7 @@ def apply_target(target):
@admin_required
def rollback_target(target):
"""Restore the pre-apply config and restart the engine."""
- data = request.get_json() or {}
+ data = json_object()
resolved, err = _build_target(target, data)
if err:
return err
diff --git a/backend/app/api/ddns.py b/backend/app/api/ddns.py
index ed36809b..78fc8b43 100644
--- a/backend/app/api/ddns.py
+++ b/backend/app/api/ddns.py
@@ -26,8 +26,9 @@ def list_hosts():
def create_host():
if not _admin():
return jsonify({'error': 'Admin access required'}), 403
+ data = json_object()
try:
- host = DdnsService.create_host(request.get_json() or {})
+ host = DdnsService.create_host(data)
# Return the token once, on creation — it is masked everywhere else.
return jsonify(host.to_dict(include_token=True)), 201
except ValueError as e:
diff --git a/backend/app/api/dns_zones.py b/backend/app/api/dns_zones.py
index 75d4e5a0..e4732316 100644
--- a/backend/app/api/dns_zones.py
+++ b/backend/app/api/dns_zones.py
@@ -74,7 +74,7 @@ def create_zone():
user = get_current_user()
if not user or not user.is_admin:
return jsonify({'error': 'Admin access required'}), 403
- data = request.get_json()
+ data = json_object()
try:
zone = DNSZoneService.create_zone(data)
return jsonify(zone.to_dict()), 201
@@ -108,7 +108,7 @@ def create_record(zone_id):
user = get_current_user()
if not user or not user.is_admin:
return jsonify({'error': 'Admin access required'}), 403
- data = request.get_json()
+ data = json_object()
try:
record = DNSZoneService.create_record(zone_id, data)
return jsonify(record.to_dict()), 201
@@ -122,7 +122,7 @@ def update_record(record_id):
user = get_current_user()
if not user or not user.is_admin:
return jsonify({'error': 'Admin access required'}), 403
- data = request.get_json()
+ data = json_object()
record = DNSZoneService.update_record(record_id, data)
if not record:
return jsonify({'error': 'Record not found'}), 404
diff --git a/backend/app/api/fleet_monitor.py b/backend/app/api/fleet_monitor.py
index d112ce9b..46047c11 100644
--- a/backend/app/api/fleet_monitor.py
+++ b/backend/app/api/fleet_monitor.py
@@ -11,6 +11,7 @@ from flask_jwt_extended import jwt_required
from app.services.fleet_monitor_service import fleet_monitor_service
from app.middleware.rbac import admin_required, get_current_user
+from app.api._request import json_object
fleet_monitor_bp = Blueprint('fleet_monitor', __name__)
@@ -94,7 +95,7 @@ def get_thresholds():
@admin_required
def create_threshold():
"""Create or update an alert threshold."""
- data = request.get_json()
+ data = json_object()
result = fleet_monitor_service.upsert_threshold(data)
if 'error' in result:
return jsonify(result), 400
diff --git a/backend/app/api/git.py b/backend/app/api/git.py
index 5795208b..81cb809b 100644
--- a/backend/app/api/git.py
+++ b/backend/app/api/git.py
@@ -106,7 +106,7 @@ def get_webhook(webhook_id):
@admin_required
def update_webhook(webhook_id):
"""Update a webhook."""
- data = request.get_json() or {}
+ data = json_object()
result = WebhookService.update_webhook(webhook_id, data)
diff --git a/backend/app/api/monitoring.py b/backend/app/api/monitoring.py
index d6f8ca56..d1a15d30 100644
--- a/backend/app/api/monitoring.py
+++ b/backend/app/api/monitoring.py
@@ -108,7 +108,7 @@ def get_thresholds():
@admin_required
def update_thresholds():
"""Update alert thresholds."""
- data = request.get_json()
+ data = json_object()
if not data:
return jsonify({'error': 'No data provided'}), 400
diff --git a/backend/app/api/monitors.py b/backend/app/api/monitors.py
index 5824f9aa..4e5275bb 100644
--- a/backend/app/api/monitors.py
+++ b/backend/app/api/monitors.py
@@ -53,7 +53,7 @@ def get_stats():
@monitors_bp.route('/', methods=['POST'])
@permission_required('monitoring', 'write')
def create_monitor():
- data = request.get_json() or {}
+ data = json_object()
monitor = MonitorService.create(data)
return jsonify(monitor.to_dict()), 201
@@ -70,7 +70,7 @@ def get_monitor(monitor_id):
@monitors_bp.route('/<int:monitor_id>', methods=['PATCH', 'PUT'])
@permission_required('monitoring', 'write')
def update_monitor(monitor_id):
- data = request.get_json() or {}
+ data = json_object()
monitor = MonitorService.update(monitor_id, data)
if not monitor:
raise NotFoundError('Monitor not found', code='monitor_not_found')
@@ -162,7 +162,7 @@ def create_incident():
@monitors_bp.route('/incidents/<int:incident_id>', methods=['PATCH', 'PUT'])
@permission_required('monitoring', 'write')
def update_incident(incident_id):
- incident = MonitorService.update_incident(incident_id, request.get_json() or {})
+ incident = MonitorService.update_incident(incident_id, json_object())
if not incident:
return {'error': 'Incident not found'}, 404
return jsonify(incident.to_dict())
diff --git a/backend/app/api/notifications.py b/backend/app/api/notifications.py
index cd6ddb7d..f8d2c74e 100644
--- a/backend/app/api/notifications.py
+++ b/backend/app/api/notifications.py
@@ -483,7 +483,7 @@ def list_email_providers():
@admin_required
def add_email_provider():
"""Add an email provider, then validate its credentials."""
- data = request.get_json() or {}
+ data = json_object()
try:
provider = EmailProviderService.add_provider(data, user_id=int(get_jwt_identity()))
except ValueError as exc:
@@ -505,7 +505,7 @@ def test_email_provider(provider_id):
def update_email_provider(provider_id):
"""Update a provider's usage flags (uses_notifications / uses_relay /
relay_priority). uses_relay applies only to SMTP."""
- row = EmailProviderService.update_usage(provider_id, request.get_json() or {})
+ row = EmailProviderService.update_usage(provider_id, json_object())
if row is None:
return jsonify({'error': 'Provider not found'}), 404
return jsonify({'success': True, 'provider': row.to_dict()}), 200
diff --git a/backend/app/api/pairing.py b/backend/app/api/pairing.py
index eb909e6c..269df53d 100644
--- a/backend/app/api/pairing.py
+++ b/backend/app/api/pairing.py
@@ -121,7 +121,7 @@ def poll():
# given enrollment, so read it once before the long-poll loop.
signature = request.headers.get('X-Enrollment-Signature')
if not signature and request.is_json:
- signature = (request.get_json(silent=True) or {}).get('signature')
+ signature = json_object(optional=True).get('signature')
deadline = time.time() + 25.0 # leave headroom under typical proxy timeouts
poll_interval = 1.0
diff --git a/backend/app/api/previews.py b/backend/app/api/previews.py
index ad5c2f54..08761d88 100644
--- a/backend/app/api/previews.py
+++ b/backend/app/api/previews.py
@@ -6,12 +6,13 @@
Mounted by the host at ``/api/v1/apps`` so every route here is nested under an
application id, e.g. ``GET /api/v1/apps/<app_id>/previews``.
"""
-from flask import Blueprint, request, jsonify
+from flask import Blueprint, jsonify
from flask_jwt_extended import jwt_required
from app.models.application_preview import ApplicationPreview
from app.services.preview_service import PreviewService
from app.api._access import require_app
+from app.api._request import json_object
previews_bp = Blueprint('previews', __name__)
@@ -42,7 +43,7 @@ def get_preview_settings(app_id):
def update_preview_settings(app_id):
"""Enable/disable previews and set the domain template + TTL for an app."""
app = require_app(app_id, write=True, conceal=True)
- data = request.get_json(silent=True) or {}
+ data = json_object(optional=True)
result = PreviewService.enable_previews(app_id, data)
return jsonify(result), 200
diff --git a/backend/app/api/registrars.py b/backend/app/api/registrars.py
index 3f62a49a..d4c1d8af 100644
--- a/backend/app/api/registrars.py
+++ b/backend/app/api/registrars.py
@@ -5,11 +5,12 @@ available to any authenticated user so the Domains page and Connections cards
can show "what we own and when it lapses".
"""
-from flask import Blueprint, request, jsonify
+from flask import Blueprint, jsonify
from flask_jwt_extended import jwt_required
from app.services.registrar_service import RegistrarService
from app.middleware.rbac import admin_required, get_current_user
+from app.api._request import json_object
registrars_bp = Blueprint('registrars', __name__)
@@ -27,7 +28,7 @@ def add_connection():
user = get_current_user()
if not user or not user.is_admin:
return jsonify({'error': 'Admin access required'}), 403
- data = request.get_json() or {}
+ data = json_object()
try:
conn = RegistrarService.add_connection(data, user.id)
except ValueError as e:
diff --git a/backend/app/api/security.py b/backend/app/api/security.py
index 25d35a6e..ed3454f3 100644
--- a/backend/app/api/security.py
+++ b/backend/app/api/security.py
@@ -250,7 +250,7 @@ def fim_set_app_optins():
from app.services.file_integrity_service import (
FileIntegrityService, FileIntegrityScopeError,
)
- data = request.get_json(silent=True)
+ data = json_object(optional=True)
if not data or 'app_ids' not in data:
return jsonify({'error': 'app_ids required'}), 400
try:
diff --git a/backend/app/api/server_templates.py b/backend/app/api/server_templates.py
index 2c189500..a846197d 100644
--- a/backend/app/api/server_templates.py
+++ b/backend/app/api/server_templates.py
@@ -76,7 +76,7 @@ def update_template(template_id):
if not user or not user.is_admin:
return jsonify({'error': 'Admin access required'}), 403
- data = request.get_json()
+ data = json_object()
template = ServerTemplateService.update_template(template_id, data)
if not template:
raise not_found('template')
diff --git a/backend/app/api/servers.py b/backend/app/api/servers.py
index 04023738..406be576 100644
--- a/backend/app/api/servers.py
+++ b/backend/app/api/servers.py
@@ -457,7 +457,7 @@ def set_server_workspace(server_id):
if server.workspace_id and not WorkspaceService.can_write_in_workspace(user, server.workspace_id):
raise PermissionDeniedError("You have read-only access to this server's workspace")
- target = (request.get_json() or {}).get('workspace_id')
+ target = json_object().get('workspace_id')
if target in (None, '', 'default'):
ws_id = WorkspaceService.ensure_default_workspace().id
else:
diff --git a/backend/app/api/servers_agents.py b/backend/app/api/servers_agents.py
index 368b8200..bfdce7c3 100644
--- a/backend/app/api/servers_agents.py
+++ b/backend/app/api/servers_agents.py
@@ -513,7 +513,7 @@ def trigger_agent_update(server_id):
action='agent:update',
params={
'version': release['version'],
- 'force': request.get_json().get('force', False) if request.get_json() else False
+ 'force': json_object(optional=True).get('force', False)
},
timeout=60.0 # Updates may take a while
)
diff --git a/backend/app/api/source_connections.py b/backend/app/api/source_connections.py
index ebb0dddf..6c87a7d9 100644
--- a/backend/app/api/source_connections.py
+++ b/backend/app/api/source_connections.py
@@ -126,7 +126,7 @@ def github_admin_config():
def update_github_admin_config():
user = get_current_user()
result = SourceConnectionService.update_github_config(
- request.get_json() or {},
+ json_object(),
user_id=user.id if user else None,
)
return jsonify(result), 200
@@ -291,7 +291,7 @@ def gitlab_admin_config():
def update_gitlab_admin_config():
user = get_current_user()
result = SourceConnectionService.update_gitlab_config(
- request.get_json() or {},
+ json_object(),
user_id=user.id if user else None,
)
return jsonify(result), 200
@@ -423,7 +423,7 @@ def bitbucket_admin_config():
def update_bitbucket_admin_config():
user = get_current_user()
result = SourceConnectionService.update_bitbucket_config(
- request.get_json() or {},
+ json_object(),
user_id=user.id if user else None,
)
return jsonify(result), 200
diff --git a/backend/app/api/templates.py b/backend/app/api/templates.py
index 5525f52f..90beec89 100644
--- a/backend/app/api/templates.py
+++ b/backend/app/api/templates.py
@@ -627,7 +627,7 @@ def export_repo_index():
@admin_required
def create_local_template():
"""Create a local template."""
- data = request.get_json()
+ data = json_object()
if not data:
return jsonify({'error': 'No data provided'}), 400
diff --git a/backend/app/api/views.py b/backend/app/api/views.py
index c7626edf..42b6d053 100644
--- a/backend/app/api/views.py
+++ b/backend/app/api/views.py
@@ -34,7 +34,7 @@ def create_view():
@views_bp.route('/<int:view_id>', methods=['PUT'])
@jwt_required()
def update_view(view_id):
- body = request.get_json(silent=True) or {}
+ body = json_object(optional=True)
view = saved_view_service.update_view(get_jwt_identity(), view_id, body)
return jsonify(view)
diff --git a/backend/app/api/workspaces.py b/backend/app/api/workspaces.py
index db720241..18b977de 100644
--- a/backend/app/api/workspaces.py
+++ b/backend/app/api/workspaces.py
@@ -55,7 +55,7 @@ def get_workspace(workspace_id):
@admin_required
def create_workspace():
user = get_current_user()
- data = request.get_json()
+ data = json_object()
if not data:
return jsonify({'error': 'Request body required'}), 400
try:
@@ -78,7 +78,7 @@ def update_workspace(workspace_id):
if role not in ['owner', 'admin'] and not user.is_admin:
return jsonify({'error': 'Insufficient permissions'}), 403
- data = request.get_json()
+ data = json_object()
ws = WorkspaceService.update_workspace(workspace_id, data)
if not ws:
return jsonify({'error': 'Workspace not found'}), 404
diff --git a/backend/tests/test_json_object_body.py b/backend/tests/test_json_object_body.py
index 0236245d..0d60a9e5 100644
--- a/backend/tests/test_json_object_body.py
+++ b/backend/tests/test_json_object_body.py
@@ -30,6 +30,17 @@ ROUTES = [
('put', '/api/v1/servers/{sid}/allowed-ips'),
('post', '/api/v1/servers/fleet/upgrade'),
('post', '/api/v1/servers/fleet/rollout'),
+ # Bodies handed straight to a service that reads them as a dict.
+ ('put', '/api/v1/servers/{sid}/workspace'),
+ ('post', '/api/v1/monitors'),
+ ('post', '/api/v1/workspaces/'),
+ ('post', '/api/v1/dns/'),
+ ('post', '/api/v1/ddns/hosts'),
+ ('post', '/api/v1/registrars/connections'),
+ ('post', '/api/v1/agent-plugins/'),
+ ('put', '/api/v1/backups/config'),
+ ('post', '/api/v1/fleet-monitor/thresholds'),
+ ('put', '/api/v1/monitoring/thresholds'),
]