Skip to content

Commit

Permalink
Document the valid settings for the AUTOCREATE variable in the WSGI app
Browse files Browse the repository at this point in the history
Also, warn when an unknown value is used.

Fixes #342
  • Loading branch information
jelmer committed Aug 30, 2024
1 parent 8c9b4d1 commit f754894
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 1 addition & 3 deletions docs/source/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ To run in docker interactively, try something like:
The following environment variables are supported by the docker image:

* ``CURRENT_USER_PRINCIPAL``: path to current user principal; defaults to "/$USER"
* ``AUTOCREATE``: whether to automatically create missing directories ("yes" or "no")
* ``DEFAULTS``: whether to create a default directory hierarch with one
calendar and one addressbook ("yes" or "no")
* ``AUTOCREATE``: whether to automatically create missing directories ("defaults", "empty")
* ``ROUTE_PREFIX``: HTTP prefix under which Xandikos should run

Running from kubernetes
Expand Down
21 changes: 18 additions & 3 deletions xandikos/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,34 @@

from .web import XandikosApp, XandikosBackend

create_defaults = False

autocreate_str = os.getenv("AUTOCREATE")
if autocreate_str == "defaults":
logging.warning("Creating default collections.")
create_defaults = True
autocreate = True
elif autocreate_str in ("empty", "yes"):
autocreate = True
elif autocreate_str in (None, "no"):
autocreate = False
else:
logging.warning("Unknown value for AUTOCREATE: %r", autocreate_str)
autocreate = False

backend = XandikosBackend(path=os.environ["XANDIKOSPATH"])
if not os.path.isdir(backend.path):
if os.getenv("AUTOCREATE"):
if autocreate:
os.makedirs(os.environ["XANDIKOSPATH"])
else:
logging.warning("%r does not exist.", backend.path)

current_user_principal = os.environ.get("CURRENT_USER_PRINCIPAL", "/user/")
if not backend.get_resource(current_user_principal):
if os.getenv("AUTOCREATE"):
if autocreate:
backend.create_principal(
current_user_principal,
create_defaults=os.environ["AUTOCREATE"] == "defaults",
create_defaults=create_defaults
)
else:
logging.warning(
Expand Down

0 comments on commit f754894

Please sign in to comment.