From 126713c84af125b53e2329181c6478fceaa4fcc7 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Sun, 17 Aug 2025 15:24:23 +0100 Subject: [PATCH] Fix environment variable config overriding --- smsbot/cli.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/smsbot/cli.py b/smsbot/cli.py index 93cf3b9..76e0d3a 100644 --- a/smsbot/cli.py +++ b/smsbot/cli.py @@ -15,6 +15,10 @@ from smsbot.utils import get_smsbot_version from smsbot.webhook import TwilioWebhookHandler +# Prefix of the environment variables to override config values +ENVIRONMENT_PREFIX = "SMSBOT_" + + def main(): parser = argparse.ArgumentParser("smsbot") parser.add_argument( @@ -44,9 +48,11 @@ def main(): # Override with environment variables, named SMSBOT_
_ for key, value in os.environ.items(): - if key.startswith("SMSBOT_"): - logging.debug("Overriding config %s with value %s", key, value) - section, option = key[7:].split("_", 1) + if key.startswith(ENVIRONMENT_PREFIX): + section, option = key[7:].lower().split("_", 1) + logging.debug("Overriding config %s/%s = %s", section, option, value) + if not config.has_section(section): + config.add_section(section) config[section][option] = value # Validate configuration