Browse Source

Read default config from file on each registration

Previously DEFAULT_CONFIG was cached at import time, so changes via
admin panel required backend restart. Now reads fresh from file.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
root 2 weeks ago
parent
commit
fc74b5fc2b
1 changed files with 9 additions and 7 deletions
  1. 9 7
      backend/app/api/v1/registration.py

+ 9 - 7
backend/app/api/v1/registration.py

@@ -3,7 +3,6 @@ Device registration endpoint.
 """
 """
 
 
 import asyncio
 import asyncio
-import copy
 import json
 import json
 import secrets
 import secrets
 from base64 import b64encode
 from base64 import b64encode
@@ -23,10 +22,14 @@ from app.utils.ssh_keys import sync_authorized_keys
 
 
 router = APIRouter()
 router = APIRouter()
 
 
-# Load default config from JSON file
+# Path to default config file
 DEFAULT_CONFIG_PATH = Path(__file__).parent.parent.parent / "default_config.json"
 DEFAULT_CONFIG_PATH = Path(__file__).parent.parent.parent / "default_config.json"
-with open(DEFAULT_CONFIG_PATH, "r") as f:
-    DEFAULT_CONFIG = json.load(f)
+
+
+def _load_default_config() -> dict:
+    """Load default config from file (not cached, always fresh)."""
+    with open(DEFAULT_CONFIG_PATH, "r") as f:
+        return json.load(f)
 
 
 
 
 class RegistrationRequest(BaseModel):
 class RegistrationRequest(BaseModel):
@@ -118,9 +121,8 @@ async def register_device(
             detail="Registration disabled. Contact administrator.",
             detail="Registration disabled. Contact administrator.",
         )
         )
 
 
-    # Create new device with default config
-    # Deep copy to avoid modifying the global default
-    device_config = copy.deepcopy(DEFAULT_CONFIG)
+    # Create new device with default config (read fresh from file)
+    device_config = _load_default_config()
 
 
     # Add SSH public key if provided
     # Add SSH public key if provided
     if data.ssh_public_key:
     if data.ssh_public_key: