Let the console add and remove printers; keep them in a local SQLite store

The only way to give a gateway a printer was to edit printers.toml and
restart it. A printer added from the console now arrives as a
provision_printer message, is checked by actually connecting to it (so a
mistyped access code is reported to the operator, not discovered later),
and only then is saved to the gateway's own SQLite file and joined to the
running fleet - no restart. remove_printer undoes it. Both are answered
with a command_result carrying the request id.

The access code exists only on the gateway: the cloud relays it once and
keeps nothing, which is the platform's rule for printer credentials. The
store file is created owner-only; the message type's Debug and the fleet
entry's Debug redact the credential; and an unparseable message from the
cloud is no longer logged with its payload, because the message that
fails to parse is exactly the one carrying an access code.

The cloud may not choose a certificate path or serial port on the
gateway's disk, so provision_printer cannot carry them.

Startup now reads printers.toml (strict, as before; a missing file is fine)
and the store (a bad stored entry is skipped, not fatal), so the gateway
comes up with its fleet with the API unreachable. Discovery treats stored
printers as already configured. rusqlite (MIT, bundled SQLite) passes
cargo deny.
This commit is contained in:
2026-10-29 15:02:48 +00:00
parent 6c60bd1f70
commit 9dff600160
13 changed files with 724 additions and 27 deletions
+20 -2
View File
@@ -32,7 +32,12 @@ use crate::uplink::ClientMessage;
/// long-running tasks. With discovery off it parks on a future that never
/// completes, which costs nothing and keeps the "every arm runs forever"
/// property of that `select!` true.
pub async fn run(settings: DiscoverySettings, printers_path: String, outbound: Sender<ClientMessage>) {
pub async fn run(
settings: DiscoverySettings,
printers_path: String,
store: Option<std::sync::Arc<crate::store::Store>>,
outbound: Sender<ClientMessage>,
) {
if !settings.enabled {
tracing::info!("printer discovery is off (discovery.enabled); not scanning this network");
std::future::pending::<()>().await;
@@ -64,7 +69,20 @@ pub async fn run(settings: DiscoverySettings, printers_path: String, outbound: S
// restart - but someone who has *edited* the file and not restarted
// should not keep being offered the printer they just configured.
let configured = match crate::fleet::configured(std::path::Path::new(&printers_path)) {
Ok(configured) => configured,
Ok(mut configured) => {
// Printers added from the console live in the store, not the
// file, and are just as "already configured".
if let Some(store) = &store {
match store.printers() {
Ok(stored) => configured.add_entries(stored),
Err(err) => {
tracing::warn!(%err, "cannot read the local store; skipping this discovery pass");
continue;
}
}
}
configured
}
// Fail the pass rather than report against an empty set. The
// alternative offers every printer the farm already runs as a
// fresh find, which is worse than no report: it is a list of