Previous values (adamaps-ingest-2026, adamaps-read-2026, mapnet-ingest-2026) were inline defaults across adamaps + adacam-api + varroa. The ingest key was briefly anon-visible during the 2026-05-27 Forgejo public-flip when adacam-api + varroa were public for a short window before the leak was spotted. New values live in Vaultwarden: - AdaMaps — API_KEY (ingest) - AdaMaps — READ_KEY Validators now hard-fail at boot if the env var is missing. Service is on hold today; when it resumes, both env vars must be set.
52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
"""Config management for adacam-api."""
|
|
import json
|
|
import os
|
|
import uuid
|
|
|
|
CONFIG_PATH = "/data/adacam/config.json"
|
|
FIRMWARE_VERSION = "adacam-1.0.0"
|
|
|
|
_defaults = {
|
|
"device_id": None,
|
|
"adamaps_key": "",
|
|
"adamaps_api": "https://api.adamaps.org",
|
|
"ap_interface": "wlp1s0f0",
|
|
"tunnel_host": "",
|
|
"tunnel_user": "",
|
|
"tunnel_port": 2222,
|
|
}
|
|
|
|
_config = None
|
|
|
|
|
|
def load():
|
|
"""Load config from disk, creating defaults if needed."""
|
|
global _config
|
|
os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
|
|
|
|
if os.path.exists(CONFIG_PATH):
|
|
with open(CONFIG_PATH) as f:
|
|
_config = {**_defaults, **json.load(f)}
|
|
else:
|
|
_config = _defaults.copy()
|
|
|
|
# Generate device_id on first run
|
|
if not _config.get("device_id"):
|
|
_config["device_id"] = str(uuid.uuid4())
|
|
save()
|
|
|
|
return _config
|
|
|
|
|
|
def save():
|
|
"""Persist config to disk."""
|
|
os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
|
|
with open(CONFIG_PATH, "w") as f:
|
|
json.dump(_config, f, indent=2)
|
|
|
|
|
|
def get(key, default=None):
|
|
"""Get a config value."""
|
|
if _config is None:
|
|
load()
|
|
return _config.get(key, default)
|