Files
WoW-Hybrid-gateway/ops/source_local_profile.py
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

30 lines
1.5 KiB
Python

"""Validate explicit build-time endpoints for a local Source client."""
from ipaddress import IPv4Address, IPv4Network
_LOCAL = tuple(IPv4Network(x) for x in ('127.0.0.0/8', '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'))
def endpoints(profile, auth_host=None, auth_port=None, realm_host=None, realm_port=None):
values = (auth_host, auth_port, realm_host, realm_port)
if profile != 5:
if any(value is not None for value in values):
raise ValueError('Local endpoints require Source profile 5')
return None
if not all(value is not None for value in values):
raise ValueError('Explicit auth and realm IPv4 addresses and ports are required')
def local(value):
if not isinstance(value, str):
raise ValueError('Local addresses must be numeric IPv4 strings')
try:
address = IPv4Address(value)
except ValueError as error:
raise ValueError('Local addresses must be numeric IPv4 strings') from error
if not any(address in net for net in _LOCAL):
raise ValueError('Local address must be loopback or RFC1918')
return str(address)
def port(value):
if type(value) is not int or not 1 <= value <= 65535:
raise ValueError('Port must be an integer between 1 and 65535')
return value
return {'auth_host':local(auth_host), 'auth_port':port(auth_port),
'realm_host':local(realm_host), 'realm_port':port(realm_port)}