From 785a445b4342cf673c004fc06497c60a1b30fd5c Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 30 Apr 2024 15:18:39 -0400 Subject: [PATCH] Add support for loading configurations values from systemd credentials --- cmsmanage/settings.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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()