diff --git a/cmsmanage/settings.py b/cmsmanage/settings.py index 8d03638..172105b 100644 --- a/cmsmanage/settings.py +++ b/cmsmanage/settings.py @@ -1,3 +1,4 @@ +import os from pathlib import Path from django.core import validators @@ -8,6 +9,17 @@ BASE_DIR = Path(__file__).resolve().parent.parent class Base(Configuration): + @classmethod + def pre_setup(cls): + super().pre_setup() + + # load systemd credentials, as per https://systemd.io/CREDENTIALS/ + credentials_directory = os.getenv("CREDENTIALS_DIRECTORY") + if credentials_directory is not None: + for credential in Path(credentials_directory).iterdir(): + if credential.name.isupper(): + os.environ.setdefault(credential.name, credential.read_text()) + @classmethod def setup(cls): super().setup()