STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
stardesign.userdata Namespace Reference

Classes

class  UserData

Functions

str _sanitize (str part, *, str fallback)
str slugify (str name)
str slug_user (str email)

Variables

str _DEV_USER = "local"
 _UNSAFE = re.compile(r"[^a-z0-9._@-]+")

Detailed Description

Per-user data storage, keyed on the caller's identity.

Identity comes from the ``X-Auth-Email`` header Caddy injects in production. The
app never gates on it -- Caddy is the gate; this only decides *whose* folder to
read and write. With no Caddy in front (local dev) there is no header, so the
user falls back to ``local`` and everything lands in a gitignored ``.userdata/``
beside the app. A missing header is never a rejection.

Layout, under ``USERDATA_DIR`` (prod: a mounted volume; dev: ``<subproject>/.userdata``)::

    <user>/<app>/index.json          -- the user's design list
    <user>/<app>/<doc-id>/current.json
    <user>/<app>/configs/<slug>.json -- the older named-config library

Designs are shared across users (see :mod:`stardesign.documents`): every design
tool mounts one volume, so "list another user's designs, then copy one" is just
reading sibling ``<user>/`` folders -- which is what this layout was chosen for.
Nothing here gates access; that decision lives in the router.

One :class:`UserData` per app binds the ``<app>`` segment, so callers never pass
it. Each app's ``backend/userdata.py`` is a few lines binding this and
re-exporting the methods under their original names, which is what lets every
existing ``userdata.current_user(request)`` call site stay exactly as it was.

Function Documentation

◆ _sanitize()

str stardesign.userdata._sanitize ( str part,
* ,
str fallback )
protected

◆ slug_user()

str stardesign.userdata.slug_user ( str email)
Normalize an email into the directory segment that identifies its owner.

Exactly the transform :meth:`UserData.current_user` applies to the header, so
an ``?owner=`` query param and the injected identity compare without any
special-casing -- which is what keeps an ownership check from hinging on two
slightly different normalizations.

Definition at line 57 of file userdata.py.

References _sanitize().

◆ slugify()

str stardesign.userdata.slugify ( str name)
Filename-safe slug from a user-given name; ``""`` if nothing usable.

Definition at line 52 of file userdata.py.

References _sanitize().

Variable Documentation

◆ _DEV_USER

str stardesign.userdata._DEV_USER = "local"
protected

Definition at line 37 of file userdata.py.

◆ _UNSAFE

stardesign.userdata._UNSAFE = re.compile(r"[^a-z0-9._@-]+")
protected

Definition at line 43 of file userdata.py.