From 3238fb6d6ea0c49162ddf9c382e28a5609a9cc5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Da=C3=9Fler?= Date: Sun, 26 May 2024 16:14:15 +0200 Subject: [PATCH] feat: Using docker secrets - put file contents to env value --- .../src/spiffworkflow_backend/config/default.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/config/default.py b/spiffworkflow-backend/src/spiffworkflow_backend/config/default.py index e2b926f68..be04cbb24 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/config/default.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/config/default.py @@ -15,6 +15,16 @@ def config_from_env(variable_name: str, *, default: str | bool | int | None = No value_from_env = None value_to_return: str | bool | int | None = value_from_env + # using docker secrets - put file contents to env value + if variable_name.endswith("_FILE"): + value_from_file = default if value_from_env is None else value_from_env + if value_from_file.startswith("/run/secrets"): + # rewrite variable name: remove _FILE + variable_name = variable_name.removesuffix("_FILE") + print(variable_name) + with open(value_from_file) as f: + value_to_return = f.readline() + if value_from_env is not None: if isinstance(default, bool): if value_from_env.lower() == "true":