From c177ea56ea477b61d85a7fe16dc0189b3c4e36e0 Mon Sep 17 00:00:00 2001 From: chapeau Date: Fri, 2 Aug 2024 16:21:58 +0200 Subject: [PATCH] review --- config.py | 15 +++++++-------- templates/wg-pn.conf.j2 | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/config.py b/config.py index 46b4422..5c4e55e 100644 --- a/config.py +++ b/config.py @@ -6,16 +6,15 @@ from dataclasses import dataclass, InitVar class Peer: public_key: str endpoint: str | None - allowed_ips: str | None = None + allowed_ips: list = [] untranslated_networks: InitVar(str | None) = None local_translated_range: InitVar(str) wireguard_address: InitVar(str) def __post_init__(self): - allowed = [self.local_translated_range, wireguard_address] + self.allowed_ips = [self.local_translated_range, wireguard_address] if untranslated_networks != None: - allowed.append(untranslated_networks) - self.allowed_ips = ", ".join(allowed) + self.allowed_ips.append(untranslated_networks) @dataclass class Network: @@ -58,7 +57,7 @@ class Config: default_dns: DNSServer | None = None dns_servers: dict = {} remote_networks: dict = {} - peers: array = [] + peers: list = [] local_wireguard_address: str = "" def __post_init__(self, default_dns_address, default_dns_port, data): @@ -106,20 +105,20 @@ class Config: ) def dns_server(self, qname): - # Guess which DNS server call from the requested domain name + """Guess which DNS server call from the requested domain name""" for dns in self.dns_servers.values(): if dns.is_same_zone(qname): return dns return self.default_dns def translate(self, ip, network): - # Translate if required given ip from given network + """Translate if required given ip from given network""" if IPv4Address(ip) in self.networks[network].local_range: return self.networks[network].translation_dict[ip] return ip def untranslate(self, ip, network): - # Give back the original ip from a translated one from given network + """Give back the original ip from a translated one from given network""" if IPv4Address(ip) in self.networks[network].local_translated_range: return self.networks[network].untranslation_dict[ip] return ip diff --git a/templates/wg-pn.conf.j2 b/templates/wg-pn.conf.j2 index ce6e773..3bc2216 100644 --- a/templates/wg-pn.conf.j2 +++ b/templates/wg-pn.conf.j2 @@ -9,6 +9,6 @@ PublicKey = {{ peer.public_key }} {%- if peer.endpoint is defined %} Endpoint = {{ peer.endpoint }} {%- endif %} -AllowedIPs = {{ peer.allowed_ips}} +AllowedIPs = {{ peer.allowed_ips | join(', ') }} PersistentKeepalive = 25 -{% endfor %} \ No newline at end of file +{% endfor %}