32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
"""A guest's web address (bucket + root domain), used across the hub
|
|
(plugins, Matomo, ship hosts, user settings, and the new-project plugin).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
def default_domain(deps) -> str:
|
|
"""The hub's default guest project domain (e.g. ``gabvdl.xyz``)."""
|
|
return (deps.users.defaults().get("newProjects") or {}).get("domain") or "gabvdl.xyz"
|
|
|
|
|
|
def bucket_of(user: dict) -> str:
|
|
return (user.get("bucket") or "").strip() or user["id"]
|
|
|
|
|
|
def address_of(user: dict, pol_or_domain: dict | str) -> tuple[str, str]:
|
|
"""A guest's ``(bucket, domain)``: their projects go to
|
|
``<name>.<bucket>.<domain>``. Under a root domain of their own the bucket
|
|
is only the one the owner set — blank ⇒ ``<name>.<domain>``."""
|
|
own = (user.get("domain") or "").strip()
|
|
if own:
|
|
return (user.get("bucket") or "").strip(), own
|
|
domain = pol_or_domain["domain"] if isinstance(pol_or_domain, dict) else (pol_or_domain or "gabvdl.xyz")
|
|
return bucket_of(user), domain
|
|
|
|
|
|
def base_of(bucket: str, domain: str) -> str:
|
|
"""What follows a project's label: ``<bucket>.<domain>``, or the bare
|
|
domain when there's no bucket."""
|
|
return f"{bucket}.{domain}" if bucket else domain
|