refactor(backend): clean up models setup, improve ip utils, add adr docs
- Extract ADR documents for architectural decisions (SQLite, FastAPI, React, APScheduler, Scheduler) - Refactor setup.py: improve code structure and readability - Add IP validation utilities with test coverage - Update frontend components (BanTable, HistoryPage) - Add pre-commit hooks and CONTRIBUTING.md - Add .editorconfig for consistent coding standards
This commit is contained in:
@@ -58,7 +58,9 @@ def normalise_ip(address: str) -> str:
|
||||
"""Return a normalised string representation of an IP address.
|
||||
|
||||
IPv6 addresses are compressed to their canonical short form.
|
||||
IPv4 addresses are returned unchanged.
|
||||
IPv4-mapped IPv6 addresses (e.g. ``::ffff:192.168.1.1``) are converted
|
||||
to their IPv4 equivalent (``192.168.1.1``).
|
||||
Plain IPv4 addresses are returned unchanged.
|
||||
|
||||
Args:
|
||||
address: A valid IP address string.
|
||||
@@ -69,7 +71,10 @@ def normalise_ip(address: str) -> str:
|
||||
Raises:
|
||||
ValueError: If *address* is not a valid IP address.
|
||||
"""
|
||||
return str(ipaddress.ip_address(address))
|
||||
ip = ipaddress.ip_address(address)
|
||||
if isinstance(ip, ipaddress.IPv6Address) and ip.ipv4_mapped:
|
||||
return str(ip.ipv4_mapped)
|
||||
return str(ip)
|
||||
|
||||
|
||||
def normalise_network(cidr: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user