Make everything keyword only
This commit is contained in:
parent
0257a5a721
commit
88d3a13dc6
44
woven.py
44
woven.py
|
@ -25,8 +25,8 @@ from cattrs.errors import ClassValidationError, IterableValidationError
|
|||
camelize = lambda name: sub(r"_([a-z])", lambda x: x.group(1).upper(), name)
|
||||
woven_config_converter = Converter()
|
||||
for cls in (IPv4Address, IPv6Address, IPv4Interface, IPv6Interface, IPv4Network, IPv6Network):
|
||||
woven_config_converter.register_structure_hook(cls, cls)
|
||||
woven_config_converter.register_unstructure_hook(cls, str)
|
||||
woven_config_converter.register_structure_hook(cls, lambda a, t: t(a))
|
||||
woven_config_converter.register_unstructure_hook(cls, lambda a: str(a))
|
||||
override_dict = lambda cls: { a.name: override(rename = camelize(a.name)) for a in fields(cls) }
|
||||
woven_config_converter.register_structure_hook_factory(has, lambda cls: make_dict_structure_fn(cls, woven_config_converter, **override_dict(cls)))
|
||||
woven_config_converter.register_unstructure_hook_factory(has, lambda cls: make_dict_unstructure_fn(cls, woven_config_converter, _cattrs_omit_if_default = True, **override_dict(cls)))
|
||||
|
@ -52,29 +52,29 @@ def validator_range(min_value: T, max_value: T) -> Callable[[T], T]:
|
|||
|
||||
@define
|
||||
class WovenMeshNode:
|
||||
address: IPv4Address | IPv6Address = field(converter = ip_address)
|
||||
gateway: IPv4Address | IPv6Address = field(converter = ip_address)
|
||||
interface: str
|
||||
ipv4_ranges: list[IPv4Network] = field(factory = list, converter = list_of_ipv4_networks)
|
||||
ipv6_ranges: list[IPv6Network] = field(factory = list, converter = list_of_ipv6_networks)
|
||||
address: IPv4Address | IPv6Address = field(converter = ip_address, kw_only = True)
|
||||
gateway: IPv4Address | IPv6Address = field(converter = ip_address, kw_only = True)
|
||||
interface: str = field(kw_only = True)
|
||||
ipv4_ranges: list[IPv4Network] = field(factory = list, converter = list_of_ipv4_networks, kw_only = True)
|
||||
ipv6_ranges: list[IPv6Network] = field(factory = list, converter = list_of_ipv6_networks, kw_only = True)
|
||||
|
||||
@define
|
||||
class WovenConfig:
|
||||
min_port: int = field(validator = validator_range(0, 0xFFFF))
|
||||
max_port: int = field(validator = validator_range(0, 0xFFFF))
|
||||
ptp_ipv4_range: IPv4Network = field(converter = IPv4Network)
|
||||
ptp_ipv6_range: IPv6Network = field(converter = IPv6Network)
|
||||
ptp_ipv4_prefix: int = field(default = 30, validator = validator_range(0, 32))
|
||||
ptp_ipv6_prefix: int = field(default = 64, validator = validator_range(0, 128))
|
||||
tunnel_prefix: str = field(default = "")
|
||||
tunnel_suffix: str = field(default = "loop")
|
||||
tunnel_separator: str = field(default = "-")
|
||||
wireguard_dir: Path = field(default = Path("/etc/wireguard"), converter = Path)
|
||||
wireguard_config_ext: str = field(default = "conf", converter = lambda x: str(x).lstrip("."))
|
||||
table: Literal["auto", "off"] = field(default = "off", validator = validator_in(["auto", "off"]))
|
||||
allowed_ips: list[str] = field(factory = lambda: ["0.0.0.0/0", "::/0"])
|
||||
keep_alive: int = field(default = 20, validator = validator_range(0, 1 << 31 - 1))
|
||||
mesh_nodes: dict[str, WovenMeshNode] = field(factory = dict)
|
||||
min_port: int = field(validator = validator_range(0, 0xFFFF), kw_only = True)
|
||||
max_port: int = field(validator = validator_range(0, 0xFFFF), kw_only = True)
|
||||
ptp_ipv4_range: IPv4Network = field(converter = IPv4Network, kw_only = True)
|
||||
ptp_ipv6_range: IPv6Network = field(converter = IPv6Network, kw_only = True)
|
||||
ptp_ipv4_prefix: int = field(default = 30, validator = validator_range(0, 32), kw_only = True)
|
||||
ptp_ipv6_prefix: int = field(default = 64, validator = validator_range(0, 128), kw_only = True)
|
||||
tunnel_prefix: str = field(default = "", kw_only = True)
|
||||
tunnel_suffix: str = field(default = "loop", kw_only = True)
|
||||
tunnel_separator: str = field(default = "-", kw_only = True)
|
||||
wireguard_dir: Path = field(default = Path("/etc/wireguard"), converter = Path, kw_only = True)
|
||||
wireguard_config_ext: str = field(default = "conf", converter = lambda x: str(x).lstrip("."), kw_only = True)
|
||||
table: Literal["auto", "off"] = field(default = "off", validator = validator_in(["auto", "off"]), kw_only = True)
|
||||
allowed_ips: list[str] = field(factory = lambda: ["0.0.0.0/0", "::/0"], kw_only = True)
|
||||
keep_alive: int = field(default = 20, validator = validator_range(0, 1 << 31 - 1), kw_only = True)
|
||||
mesh_nodes: dict[str, WovenMeshNode] = field(kw_only = True)
|
||||
|
||||
def _surround(self, val: str) -> str:
|
||||
prefix_str = f"{self.tunnel_prefix}{self.tunnel_separator}" if self.tunnel_prefix else ""
|
||||
|
|
Loading…
Reference in New Issue