#!/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]} ", 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()