Skip to content

Commit

Permalink
make sure that the port is included in the endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jnhmcknight committed Aug 23, 2022
1 parent 59cfb77 commit b5bbb3f
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion wireguard/peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Peer: # pylint: disable=too-many-instance-attributes
"""

description = None
_endpoint = None
_interface = None
_ipv6_address = None
_ipv4_address = None
Expand All @@ -56,7 +57,6 @@ class Peer: # pylint: disable=too-many-instance-attributes
_public_key = None
_keepalive = None
allowed_ips = None
endpoint = None
save_config = None
dns = None
pre_up = None
Expand Down Expand Up @@ -261,6 +261,30 @@ def port(self, value):
value = int(value)
self._port = value

@property
def endpoint(self):
"""
Returns the endpoint value
"""

if not isinstance(self._endpoint, str):
return None

# This is the easiest sure way to know if the port is already part of the endpoint
# and will work for domain names, IPv4 and IPv6 addresses
if self._endpoint.endswith(f':{self.port}'):
return self._endpoint

return f'{self._endpoint}:{self.port}'

@endpoint.setter
def endpoint(self, value):
"""
Sets the endpoint value
"""

self._endpoint = value

@property
def interface(self):
"""
Expand Down

0 comments on commit b5bbb3f

Please sign in to comment.