Skip to content

Commit

Permalink
Fix logical merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
DasSkelett committed Dec 17, 2023
1 parent 4e9a53a commit 4e61b52
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion wgkex/broker/metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""},
}
Expand Down
9 changes: 6 additions & 3 deletions wgkex/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions wgkex/worker/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
7 changes: 3 additions & 4 deletions wgkex/worker/mqtt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 4e61b52

Please sign in to comment.