Files
yaris-obd/server/scripts/create_device.py
Mathieu MoranandCopilot ba682fbf3a feat: add multi-device provisioning and local remote-config UI
- add multi-device portal device management, key rotation, and sync request APIs
- add Pi settings UI for remote server URL, device name, and API key
- add local test-connection and sync-now actions
- make upload and config sync reuse dynamic shared credentials
- add Phase 25.5c migration and docs updates

Co-authored-by: Copilot <[email protected]>
2026-08-10 18:02:09 -04:00

40 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Register a new device (e.g. the Pi) and print its API key.
Run this INSIDE the api container so it shares the same DB connection env
vars already configured by docker-compose, e.g.:
docker compose exec api python3 scripts/create_device.py yaris-2013
The raw API key is only ever shown once here - copy it into the Pi's
upload-client config immediately. Only its sha256 hash is stored server-side.
"""
import sys
sys.path.insert(0, "/app")
from modules import device_registry # noqa: E402
def main():
if len(sys.argv) != 2:
print(f"usage: {sys.argv[0]} <device-name>", file=sys.stderr)
sys.exit(1)
result, errors = device_registry.create_device(sys.argv[1])
if errors:
print(f"error: {errors}", file=sys.stderr)
sys.exit(1)
print(f"Device '{result['device']['name']}' registered (id={result['device']['id']}).")
print()
print("Save these on the Pi (e.g. in db/upload_creds.env, gitignored):")
print(f" YARIS_DEVICE_NAME={result['device']['name']}")
print(f" YARIS_API_KEY={result['api_key']}")
print()
print("This key will not be shown again - only its hash is stored server-side.")
if __name__ == "__main__":
main()