fix: reuse upload credentials for device config sync

- load server sync creds from db/upload_creds.env like uploads do
- fall back from YARIS_DEVICE_KEY to existing YARIS_API_KEY
- document shared credential flow for server-synced identity
- add test coverage for sync credential fallback

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Mathieu Moran
2026-08-10 17:37:52 -04:00
co-authored by Copilot
parent 585da18225
commit 5a5058adca
4 changed files with 30 additions and 5 deletions
+13 -3
View File
@@ -10,6 +10,7 @@ import threading
import time
import requests
from dotenv import load_dotenv
from . import app_network, app_sql
@@ -18,6 +19,9 @@ _SYNC_THREAD = None
_SYNC_STOP = False
_SYNC_CONFIG_VERSION = 0 # Track last-synced version to detect changes
_RELOAD_CALLBACK = None
_BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
load_dotenv(os.path.join(_BASE_DIR, "db", "upload_creds.env"))
def _has_internet():
@@ -34,6 +38,12 @@ def _has_internet():
return False
def _server_credentials():
server_url = os.getenv("YARIS_SERVER_URL", "").rstrip("/")
device_key = os.getenv("YARIS_DEVICE_KEY") or os.getenv("YARIS_API_KEY", "")
return server_url, device_key
def start_sync():
"""Start background device config sync thread."""
global _SYNC_THREAD, _SYNC_STOP
@@ -61,8 +71,7 @@ def _sync_loop():
"""Periodically sync device config from server when internet available."""
global _SYNC_CONFIG_VERSION
server_url = os.getenv("YARIS_SERVER_URL", "")
device_key = os.getenv("YARIS_DEVICE_KEY", "")
server_url, device_key = _server_credentials()
if not server_url or not device_key:
return # Sync disabled if server URL or device key not configured
@@ -125,7 +134,8 @@ def _on_config_changed():
def is_sync_enabled():
"""Check if device config sync from server is enabled."""
return bool(os.getenv("YARIS_SERVER_URL")) and bool(os.getenv("YARIS_DEVICE_KEY"))
server_url, device_key = _server_credentials()
return bool(server_url) and bool(device_key)
def get_synced_config_version():