STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
admins.py
Go to the documentation of this file.
1"""Who is an admin: a fixed list, checked against the caller's identity.
2
3Admins may choose the team's main design and are the only ones who may change
4it (see :mod:`stardesign.documents`). The list is in code on purpose: changing
5who can rewrite the main design should be a reviewed commit, not a button.
6
7Identity is the ``X-Auth-Email`` Caddy sets after verifying the session, and
8Caddy strips any copy the client sent (see deploy/caddy/Caddyfile), so the
9comparison below is against an email the caller cannot choose.
10
11``STAR_ADMINS`` (comma-separated emails) adds to the list without a commit. It
12exists for dev, where there is no Caddy and every request is the ``local`` user
13(``STAR_ADMINS=local``).
14"""
15
16from __future__ import annotations
17
18import os
19
20from fastapi import Request
21
22from stardesign.userdata import UserData, slug_user
23
24#: Compared as path slugs, the same normalisation ``current_user`` applies.
25ADMIN_EMAILS = (
26 "aahilsyed72@berkeley.edu",
27 "carlosbautista@berkeley.edu",
28 "aidanrickert@berkeley.edu",
29 "manank_doshi@berkeley.edu",
30)
31
32
33def admin_slugs() -> set[str]:
34 extra = os.environ.get("STAR_ADMINS", "")
35 return {slug_user(e) for e in (*ADMIN_EMAILS, *extra.split(",")) if e.strip()}
36
37
38def is_admin(request: Request, ud: UserData) -> bool:
39 """Whether the caller is a STAR admin."""
40 return ud.current_user(request) in admin_slugs()
set[str] admin_slugs()
Definition admins.py:33
bool is_admin(Request request, UserData ud)
Definition admins.py:38