webclient
The web client of an application image, exported once per image and served by this node.
A session's page is the Selkies web client. Served by the container, it is
code of the image running on whatever origin the browser reached it on, and
on the web app's origin that code could act as the signed-in user. So the
node takes the client out of the image instead, once per image digest, with
a throwaway instance of the image that gives up web_client_path as a tar
stream (BaseProvider.export_web_client), and serves it at /<session id>/
itself; the container answers its api/ alone. The export runs after every
pull and, failing that, at the first launch of the image on this node.
Bundles live under <node_state_path>/web/<digest>/, one subdirectory per
dashboard as the image keeps them; dashboard_dir picks the one a session's
DASHBOARD names. prune removes the bundles of images no installed
application runs any more.
attributelogger= logging.getLogger(__name__)attributeDEFAULT_DASHBOARD= 'selkies-dashboard'attributeMAX_BUNDLE_BYTES= 256 * 1024 * 1024attributeEXPORT_TIMEOUT= 300funcbundles_root() -> strReturn the directory the exported clients are kept under.
Returns
strfuncbundle_dir(digest) -> strReturn the directory of an image's exported client, by its digest.
paramdigeststrReturns
strfuncdashboard_dir(bundle, env) -> str | NoneReturn the directory of the dashboard a session serves, inside a bundle.
parambundlestrThe image's bundle directory.
paramenvdict[str, Any] | NoneThe session's environment, whose DASHBOARD names the dashboard.
Returns
str | NoneThe directory holding index.html: the named dashboard, the default
func_unpack(data, target, top) -> NoneUnpack an export into target, refusing anything that would land outside it.
paramdatabytesThe tar stream, gzipped or not.
paramtargetstrThe directory to fill.
paramtopstrThe name of the exported directory: entries under it, as a copy of the directory itself has them, lose that first component.
Returns
Nonefunc_export(image, digest) -> strExport an image's client into its bundle directory and return the directory.
paramimagestrparamdigeststrReturns
strfunc_digest(image) -> str | NoneReturn the digest of the image sessions of image run now, pulling or pinning it when none is known.
paramimagestrReturns
str | Nonefuncensure(image) -> strReturn the bundle directory of an image's client, exporting it when this node has none.
paramimagestrThe image reference an application runs.
Returns
strThe bundle directory.
funcexport_quietly(image) -> NoneExport an image's client after a pull, logging a failure rather than raising it.
paramimagestrReturns
Nonefuncprune(keep) -> NoneRemove the bundles of every digest not in keep.
paramkeepset[str]The digests of the images installed applications run, and of the sessions running.
Returns
Nonefuncdigests_in_use() -> set[str]Return the digests of the installed applications' images and the running sessions' bundles.
Returns
set[str]funcroot_for_session(app_image, env, required) -> str | NoneReturn the directory a new session's client is served from.
paramapp_imagestrThe image the session runs.
paramenvdict[str, Any]The session's environment, for its DASHBOARD.
paramrequiredboolWhether the session cannot be served without it: a web sign-in's session on the web app's origin.
Returns
str | NoneThe dashboard directory, or None when the client could not be