client
client
¶
Transport-only varlink client for org.terok.Clearance1.
Connects to the hub over the clearance unix socket, streams events via
a background subscriber task, and exposes verdict() for the
companion RPC channel. Doesn't know anything about notification
rendering or desktop state — that's EventSubscriber's job and
lives one module up.
Why two connections: varlink is strictly serial per connection (one
reply-at-a-time, no multiplexing). A long-lived Subscribe(more=true)
would block every Verdict() call on the same transport, so we open
one connection for the event stream and a second for the RPC path.
EventCallback = Callable[[ClearanceEvent], Awaitable[None]]
module-attribute
¶
ClearanceClient(*, socket_path=None)
¶
Thin async client for the Clearance1 varlink service.
Two async coroutines to drive:
start— open the subscribe + RPC connections and begin relaying events to the user-supplied callback. Returns once both channels are live; events arrive viaon_eventfrom then on.verdict— RPC call; returnsTrueifterok-shieldapplied the action,Falseon any refusal or shield failure. The refusal reason is logged at WARNING.
The callback runs on the same event loop as the rest of the client; exceptions it raises are logged and swallowed so one bad handler can't kill the stream for every subsequent event.
Remember the target socket; defaults to default_clearance_socket_path.
Source code in src/terok_clearance/client/client.py
start(on_event)
async
¶
Open both connections and begin relaying events to on_event.
The initial connect is awaited synchronously so callers see
start() return only after the subscription is live — a
hub that's down at startup still propagates as an exception.
Subsequent drops are handled by _run_stream's internal
reconnect loop so long-running consumers (TUI, notifier)
survive a systemctl restart terok-clearance without
restarting themselves.
Source code in src/terok_clearance/client/client.py
stop()
async
¶
Close both connections and await the stream task.
Source code in src/terok_clearance/client/client.py
poke_reconnect()
¶
Skip any in-flight reconnect back-off and retry immediately.
Idempotent; a no-op when the stream is healthy because the
event is only awaited inside _run_stream's back-off
window.
Source code in src/terok_clearance/client/client.py
verdict(container, request_id, dest, action)
async
¶
Apply action (allow / deny) to dest via the hub's Verdict RPC.
Returns True when the hub accepted and applied the verdict,
False for any refusal (unknown request_id, tuple mismatch,
invalid action, shield-exec failure). Callers typically ignore
the return value and let the subsequent verdict_applied
event drive UI updates; refusal reasons are logged at WARNING.