service
Builds and starts the patient-data API server, with no Pod involved.
This is the API child's main under Compute (ADR 0011): everything the API
needs -- the owner's username, the compute's keys, and the certificate on
disk -- exists without a Pod and without a Hub session.
Pod._run_patient_api_server calls it today, for parity while the pod still
embeds the API; that call is removed once Compute owns the API.
Imports nothing from bitfount.federated: that package's __init__ imports
Pod, which imports this module, so any such import here would be a cycle.
Module
Functions
build_and_start_patient_api_server
def build_and_start_patient_api_server( *, username: str, compute_name: str, pod_key_path: Path, compute_certificate_manager: ComputeCertificateManager,) ‑> PatientAPIStartResult:Build and start the patient-data API server.
Serves patient-eligibility data to the Trials Web App. Skipped in notebooks, when disabled via config, and when JWT authentication is not configured (so the API is never served unauthenticated).
When a hub-issued TLS certificate has already been persisted (see
ComputeCertificateManager), serves HTTPS on the compute's private IP so
the Trials Web App can reach it from another machine on the same network;
otherwise serves plain HTTP on loopback, exactly as before this
certificate lifecycle existed.
Arguments
username: The compute owner's username; the API only accepts tokens issued to it.compute_name: The compute's name, which locates its background cache and image cache on disk.pod_key_path: Path to the compute's RSA private key file, for decrypting its background cache.compute_certificate_manager: This compute's certificate manager, for locating an already-issued TLS certificate to serve, if any.
Returns
(server, fullchain_contents, confirmed). server is None if the
server is disabled/not configured/running in a notebook. confirmed
is whether the server is known to have started successfully -- True
trivially when server is None, since there is then nothing to
confirm; when server is not None, fullchain_contents (the
certificate content being served, if any) should only be trusted if
confirmed is also True.
serve_patient_api
def serve_patient_api(username: str, compute_name: str) ‑> None:The patient-data API child's main: serve, and live as long as serving.
Shared by every host of a Compute (the desktop orchestrator and
bitfount run_compute): given only who the compute is, it finds the
compute's key and whatever certificate is on disk, and serves. It never
talks to the hub; the Compute registers and renews.
Exits non-zero if the server does not come up, so the Compute (or a
container restart policy) can tell.
Arguments
username: The compute owner's username.compute_name: The compute's name, which locates its key directory and cache (the pod configuration'snametoday).
Classes
PatientAPIStartResult
class PatientAPIStartResult( server: ForwardRef('PatientAPIServer | None'), fullchain_contents: ForwardRef('str | None'), confirmed: ForwardRef('bool'),):Named tuple for patient API server start.
Variables
confirmed : bool- Alias for field number 2
fullchain_contents : str | None- Alias for field number 1
server : PatientAPIServer | None- Alias for field number 0