Skip to content

Commit 8656a56

Browse files
committed
Improve ip6 redaction
1 parent 58d50bf commit 8656a56

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

airos/data.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _redact(d: dict[str, Any]) -> dict[str, Any]:
6161
for k, v in d.items():
6262
if k in sensitive_keys:
6363
if isinstance(v, str) and (is_mac_address(v) or is_mac_address_mask(v)):
64-
# Redact only the first 6 hex characters of a MAC address
64+
# Redact only the last part of a MAC address to a dummy value
6565
redacted_d[k] = "00:11:22:33:" + v.replace("-", ":").upper()[-5:]
6666
elif isinstance(v, str) and is_ip_address(v):
6767
# Redact to a dummy local IP address
@@ -71,6 +71,21 @@ def _redact(d: dict[str, Any]) -> dict[str, Any]:
7171
):
7272
# Redact list of IPs to a dummy list
7373
redacted_d[k] = ["127.0.0.3"] # type: ignore[assignment]
74+
elif isinstance(v, list) and all(
75+
isinstance(i, dict) and "addr" in i and is_ip_address(i["addr"])
76+
for i in v
77+
):
78+
# Redact list of dictionaries with IP addresses to a dummy list
79+
redacted_list = []
80+
for item in v:
81+
redacted_item = item.copy()
82+
redacted_item["addr"] = (
83+
"127.0.0.3"
84+
if ipaddress.ip_address(redacted_item["addr"]).version == 4
85+
else "::1"
86+
)
87+
redacted_list.append(redacted_item)
88+
redacted_d[k] = redacted_list # type: ignore[assignment]
7489
else:
7590
redacted_d[k] = "REDACTED"
7691
elif isinstance(v, dict):

script/mashumaro-step-debug.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
if project_root_dir not in sys.path:
1313
sys.path.append(project_root_dir)
1414

15-
from airos.data import AirOS8Data, Remote, Station, Wireless # noqa: E402
15+
from airos.data import AirOS8Data, Interface, Remote, Station, Wireless # noqa: E402
1616

1717
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
1818
_LOGGER = logging.getLogger(__name__)
@@ -63,6 +63,15 @@ def main() -> None:
6363
wireless_obj = Wireless.from_dict(wireless_data) # noqa: F841
6464
_LOGGER.info(" -> Success! The Wireless object is valid.")
6565

66+
_LOGGER.info(" -> Checking list of Interface objects...")
67+
interfaces = data["interfaces"]
68+
interface_obj_list = [] # noqa: F841
69+
for i, interface_data in enumerate(interfaces):
70+
_LOGGER.info(" -> Checking Interface object at index %s...", i)
71+
_LOGGER.info(" Interface should be %s.", interface_data["ifname"])
72+
interface_obj = Interface.from_dict(interface_data) # noqa: F841
73+
_LOGGER.info(" Success! Interface is valid.")
74+
6675
_LOGGER.info("Attempting to deserialize full AirOS8Data object...")
6776
airos_data_obj = AirOS8Data.from_dict(data) # noqa: F841
6877
_LOGGER.info("Success! Full AirOS8Data object is valid.")

0 commit comments

Comments
 (0)