Skip to content

Instantly share code, notes, and snippets.

View spencer237's full-sized avatar

Nkenmoe Ulrich Armel spencer237

View GitHub Profile
@spencer237
spencer237 / enrollment_handler.py
Created May 21, 2026 00:01
Pi lifecycle defer MQTT creds + enrollment_wire
"""Handler for discovery.enrollment messages from CMS.
Validates the incoming signed envelope (HMAC + ts window + nonce replay),
extracts the PiEnrollmentPayload fields, and plans the side effects. The
module is pure: it never writes to disk, runs SAS commands, or publishes
MQTT itself. The caller (wiring layer in mqtt/client/thread.py) reads
``EnrollmentPlan`` and performs the apply steps in order.
Apply order expected from the caller (when plan.valid is True):
1. Write runtime.env with plan.runtime_env_updates (atomic, persistent).
@spencer237
spencer237 / enrollment_wire.py
Created May 20, 2026 23:27
Pi lifecycle SAS-after-enrollment - temporary deploy
"""Wiring glue between MQTT _on_message and the enrollment_handler/apply pair.
This module is the ONE entry point invoked by ``mqtt/client/thread.py``
when an ``discovery/{device_uid}/enrollment`` message arrives. It:
1. Decodes the JSON payload (rejects non-object).
2. Loads the Pi's persistent state (or builds an ephemeral fallback).
3. Auto-transitions BLANKBOOTSTRAPPEDDISCOVERABLE if needed, so a
freshly imaged Pi receiving its first enrollment can accept it
(state.json is wiped by smc-clone-hygiene on every boot until we