From 7aa996797204ad7933f1e0fb3e1b00d6367b71f7 Mon Sep 17 00:00:00 2001 From: DasSkelett Date: Sun, 17 Dec 2023 21:27:15 +0000 Subject: [PATCH] Fix logical merge conflicts --- wgkex/broker/metrics_test.py | 2 +- wgkex/common/utils.py | 9 ++++++--- wgkex/worker/mqtt.py | 6 ++---- wgkex/worker/mqtt_test.py | 7 +++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/wgkex/broker/metrics_test.py b/wgkex/broker/metrics_test.py index 63b25bf..520e6a9 100644 --- a/wgkex/broker/metrics_test.py +++ b/wgkex/broker/metrics_test.py @@ -12,7 +12,7 @@ def setUpClass(cls) -> None: test_config = config.Config.from_dict( { "domains": [], - "domain_prefix": "", + "domain_prefixes": "", "workers": {}, "mqtt": {"broker_url": "", "username": "", "password": ""}, } diff --git a/wgkex/common/utils.py b/wgkex/common/utils.py index 45c7b7b..8fa201c 100644 --- a/wgkex/common/utils.py +++ b/wgkex/common/utils.py @@ -48,6 +48,9 @@ def is_valid_domain(domain: str) -> bool: Returns: True if the domain is valid, False otherwise. """ - return domain in config.get_config().domains and domain.startswith( - config.get_config().domain_prefix - ) + if not domain in config.get_config().domains: + return False + for prefix in config.get_config().domain_prefixes: + if domain.startswith(prefix): + return True + return False diff --git a/wgkex/worker/mqtt.py b/wgkex/worker/mqtt.py index ef45345..caf7011 100644 --- a/wgkex/worker/mqtt.py +++ b/wgkex/worker/mqtt.py @@ -238,13 +238,11 @@ def wg_interface_name(domain: str) -> Optional[str]: cleaned_domain = None for prefix in domain_prefixes: try: - cleaned_domain = domain.split(prefix[1]) + cleaned_domain = domain.split(prefix)[1] except IndexError: continue break if not cleaned_domain: - raise ValueError( - f"Could not find a match for {domain_prefixes} on {domain}" - ) + raise ValueError(f"Could not find a match for {domain_prefixes} on {domain}") # this will not work, if we have non-unique prefix stripped domains return f"wg-{cleaned_domain}" diff --git a/wgkex/worker/mqtt_test.py b/wgkex/worker/mqtt_test.py index 1c6bf81..b17d1d6 100644 --- a/wgkex/worker/mqtt_test.py +++ b/wgkex/worker/mqtt_test.py @@ -12,12 +12,12 @@ def _get_config_mock(domains=None, mqtt=None): - test_prefix = "_ffmuc_" + test_prefixes = ["_ffmuc_", "_TEST_PREFIX2_"] config_mock = mock.MagicMock() config_mock.domains = ( - domains if domains is not None else [f"{test_prefix}domain.one"] + domains if domains is not None else [f"{test_prefixes[0]}domain.one"] ) - config_mock.domain_prefix = test_prefix + config_mock.domain_prefixes = test_prefixes if mqtt: config_mock.mqtt = mqtt return config_mock @@ -54,7 +54,6 @@ def test_connect_fails_mqtt_error(self, config_mock, mqtt_mock): with self.assertRaises(ValueError): mqtt.connect(threading.Event()) - @mock.patch.object(mqtt, "get_config") @mock.patch.object(mqtt, "get_connected_peers_count") def test_publish_metrics_loop_success(self, conn_peers_mock, config_mock):