From 1b0d9283b7bde4161ab16afe0fad8f2b21a22bfb Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Tue, 29 Jun 2021 00:23:35 +0530 Subject: [PATCH] [change] Updated WireGaurd schema to use string type for endpoint_port Using integer type for endpoint_port field does not allow using variables which is required for automatic template generation. --- docs/source/backends/openwrt.rst | 4 ++-- docs/source/backends/wireguard.rst | 2 +- netjsonconfig/backends/wireguard/schema.py | 7 ++----- netjsonconfig/backends/wireguard/wireguard.py | 4 ++-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/docs/source/backends/openwrt.rst b/docs/source/backends/openwrt.rst index 522e23988..17ee264b4 100644 --- a/docs/source/backends/openwrt.rst +++ b/docs/source/backends/openwrt.rst @@ -2363,7 +2363,7 @@ The following *configuration dictionary*: "public_key": "94a+MnZSdzHCzOy5y2K+0+Xe7lQzaa4v7lEiBZ7elVE=", "allowed_ips": ["10.0.0.1/32"], "endpoint_host": "wireguard.test.com", - "endpoint_port": 51820, + "endpoint_port": "51820", "preshared_key": "", "persistent_keepalive": 60, "route_allowed_ips": True, @@ -2525,7 +2525,7 @@ The following *configuration dictionary*: "public_key": "94a+MnZSdzHCzOy5y2K+0+Xe7lQzaa4v7lEiBZ7elVE=", "allowed_ips": ["10.0.0.1/32"], "endpoint_host": "wireguard.test.com", - "endpoint_port": 51820, + "endpoint_port": "51820", "preshared_key": "", "persistent_keepalive": 60, "route_allowed_ips": True, diff --git a/docs/source/backends/wireguard.rst b/docs/source/backends/wireguard.rst index 5601e5f1e..349f69168 100644 --- a/docs/source/backends/wireguard.rst +++ b/docs/source/backends/wireguard.rst @@ -43,7 +43,7 @@ See an example of initialization and rendering below: "allowed_ips": "10.0.0.4/32", "preshared_key": "xisFXck9KfEZga4hlkproH6+86S8ki1tmLtMtqVipjg=", "endpoint_host": "192.168.1.35", - "endpoint_port": 4908, + "endpoint_port": "4908", }, ], } diff --git a/netjsonconfig/backends/wireguard/schema.py b/netjsonconfig/backends/wireguard/schema.py index 65f15d7dd..22c58a7bc 100644 --- a/netjsonconfig/backends/wireguard/schema.py +++ b/netjsonconfig/backends/wireguard/schema.py @@ -78,15 +78,12 @@ }, "endpoint_port": { "title": "endpoint port", - "type": "integer", "description": ( "Wireguard port. Will be ignored if " "\"endpoint host\" is left empty." ), - "default": 51820, - "maximum": 65535, - "minimum": 1, - "propertyOrder": 4, + "type": "string", + "pattern": "^[0-9]*$", }, "preshared_key": { "title": "pre-shared key", diff --git a/netjsonconfig/backends/wireguard/wireguard.py b/netjsonconfig/backends/wireguard/wireguard.py index 07776a69d..e261008a3 100644 --- a/netjsonconfig/backends/wireguard/wireguard.py +++ b/netjsonconfig/backends/wireguard/wireguard.py @@ -34,8 +34,8 @@ def auto_client(cls, host='', public_key='', server={}, port=51820, **kwargs): }, 'server': { 'public_key': public_key, - 'endpoint_host': host, - 'endpoint_port': server.get('port', 51820), + 'endpoint_host': kwargs.get('vpn_host', host), + 'endpoint_port': kwargs.get('vpn_port', server.get('port', 51820)), 'allowed_ips': [kwargs.get('server_ip_network', '')], }, }