From b9762ac7d33b194771d928ba75b2695605437f66 Mon Sep 17 00:00:00 2001 From: Yusuf Ali Date: Fri, 24 Jan 2025 21:57:05 -0500 Subject: [PATCH] fix(config): migrated dot marker to _DOT_ --- servc/svc/config/__init__.py | 9 ++++++--- tests/svc/test_config.py | 10 ++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/servc/svc/config/__init__.py b/servc/svc/config/__init__.py index 3dc2057..c73b53a 100644 --- a/servc/svc/config/__init__.py +++ b/servc/svc/config/__init__.py @@ -20,6 +20,8 @@ "conf.bus.bindtoeventexchange": True, } +DOT_MARKER = os.getenv("SERVC_DOT_MARKER", "_DOT_") + class Config: _configDictionary: dict = {} @@ -50,7 +52,7 @@ def __init__(self, config_path: str | None = None): "CONF__FILE", "CONF__BUS__ROUTEMAP", ): - self.setValue(key.replace("__", ".").lower(), value) + self.setValue(key.replace("__", "."), value) self.setValue("conf.bus.instanceid", self.get("conf.instanceid")) @@ -59,7 +61,7 @@ def __init__(self, config_path: str | None = None): raise Exception("Configuration file does not match the configuration path") def get(self, key: str) -> Any: - keys = [x.replace("--", ".") for x in key.lower().split(".")] + keys = [x.replace(DOT_MARKER, ".") for x in key.split(".")] subconfig = self._configDictionary for index, subkey in enumerate(keys): @@ -71,7 +73,8 @@ def get(self, key: str) -> Any: subconfig = subconfig.get(subkey, {}) def setValue(self, key: str, value: Any): - keys = [x.replace("--", ".") for x in key.lower().split(".")] + key = key.lower().replace(DOT_MARKER.lower(), DOT_MARKER) + keys = [x.replace(DOT_MARKER, ".") for x in key.split(".")] subconfig = self._configDictionary for index, subkey in enumerate(keys): diff --git a/tests/svc/test_config.py b/tests/svc/test_config.py index 9c8b936..10a6a9b 100644 --- a/tests/svc/test_config.py +++ b/tests/svc/test_config.py @@ -18,13 +18,11 @@ def test_value(self): self.assertEqual(self.config.get("conf.bus.prefix"), "test") self.config.setValue("conf.bus.routemap.api", "test_route") - self.assertEqual(self.config.get( - "conf.bus.routemap.api"), "test_route") + self.assertEqual(self.config.get("conf.bus.routemap.api"), "test_route") - self.config.setValue("conf.bus.routemap--api", "test_route") - self.assertEqual(self.config.get( - "conf.bus.routemap--api"), "test_route") - self.assertIn("routemap.api", self.config.get('conf.bus')) + self.config.setValue("conf.bus.routemap_DOT_api", "test_route") + self.assertEqual(self.config.get("conf.bus.routemap_DOT_api"), "test_route") + self.assertIn("routemap.api", self.config.get("conf.bus")) def test_wrong_location(self): try: