1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Introduce IPNetworkSerializer to serialize allowed token IPs

This commit is contained in:
jeremystretch
2022-06-22 21:51:43 -04:00
parent e3b7bba84f
commit 3c15419bd0
6 changed files with 29 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
import ipaddress
from netaddr import IPAddress
__all__ = (
'get_client_ip',
@@ -19,7 +19,7 @@ def get_client_ip(request, additional_headers=()):
if header in request.META:
client_ip = request.META[header].split(',')[0]
try:
return ipaddress.ip_address(client_ip)
return IPAddress(client_ip)
except ValueError:
raise ValueError(f"Invalid IP address set for {header}: {client_ip}")