Skip to content

Commit

Permalink
Fix: --merge-from-custom-file overriding configs
Browse files Browse the repository at this point in the history
The `--merge-from-custom-file` option of the `clients-from-euroix`
command is supposed to merge the configurations from a local file
into the final content that it generates for clients.yml.
However, a bug was triggering an undesired behaviour, for which the
`cfg` settings from the local file were overriding those automatically
generated by the command. This was leading to the removal of information
such as max-prefix and as-set that were originally populated using the
Euro-IX records.
  • Loading branch information
pierky committed Nov 3, 2023
1 parent 56cb91f commit 11f0806
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pierky/arouteserver/config/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from copy import deepcopy
import logging
import yaml
import collections.abc


from .base import ConfigParserBase, convert_deprecated
from .validators import *
Expand Down Expand Up @@ -300,6 +302,15 @@ def inherit_from_general_cfg(dest, src, schema):
raise ConfigError()

def merge_clients(original, custom_file):

def update_dict_recursively(d, u):
for k, v in u.items():
if isinstance(v, collections.abc.Mapping):
d[k] = update_dict_recursively(d.get(k, {}), v)
else:
d[k] = v
return d

try:
new = yaml.safe_load(custom_file)
except Exception as e:
Expand Down Expand Up @@ -364,7 +375,7 @@ def merge_clients(original, custom_file):
# A client having the same IP is present in the
# list of original clients. It's the one to update
# with the settings from the custom one.
original_client.update(client)
update_dict_recursively(original_client, client)
break
else:
# No clients to update were found.
Expand Down
2 changes: 2 additions & 0 deletions tests/static/test_clients_from_euroix.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def test_merge_clients_2(self):
ip = "195.69.147.250"
client = [client for client in clients["clients"] if client["ip"] == ip][0]
assert client["cfg"]["filtering"]["irrdb"]["as_sets"] == ["AS-NFLX-V4"]
assert client["cfg"]["filtering"]["max_prefix"]["limit_ipv4"] == 42

ip = "2001:7f8:1::a500:2906:1"
client = [client for client in clients["clients"] if client["ip"] == ip][0]
Expand All @@ -213,6 +214,7 @@ def test_merge_clients_2(self):
ip = "195.69.147.250"
client = [client for client in clients["clients"] if client["ip"] == ip][0]
assert client["cfg"]["filtering"]["irrdb"]["as_sets"] == ["AS-TWO"]
assert client["cfg"]["filtering"]["max_prefix"]["limit_ipv4"] == 42

# In custom_clients_2.yml, the client is reported with
# an uppercase IPv6 address, while the one that comes
Expand Down

0 comments on commit 11f0806

Please sign in to comment.