summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJernej Jakob <jernej.jakob@gmail.com>2020-05-01 20:00:48 +0200
committerJernej Jakob <jernej.jakob@gmail.com>2020-05-04 22:59:40 +0200
commit8bdbf5fa8bf4a0134d373412bfca0a562c615a5d (patch)
tree8b1b0e70ecb45c84e731fd7916bf65900fd8d0a8
parent5b628a395fca837f9e0b3fde180c11ce0eac16a5 (diff)
downloadvyos-1x-8bdbf5fa8bf4a0134d373412bfca0a562c615a5d.tar.gz
vyos-1x-8bdbf5fa8bf4a0134d373412bfca0a562c615a5d.zip
wireguard: T2241: cleanup verify section
- make error output more user friendly - replace .format with f-strings - split into lines less than ~80 characters long
-rwxr-xr-xsrc/conf_mode/interfaces-wireguard.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/conf_mode/interfaces-wireguard.py b/src/conf_mode/interfaces-wireguard.py
index 2065278fd..820b0a724 100755
--- a/src/conf_mode/interfaces-wireguard.py
+++ b/src/conf_mode/interfaces-wireguard.py
@@ -190,13 +190,11 @@ def get_config():
def verify(wg):
- interface = wg['intf']
-
if wg['deleted']:
if wg['is_bridge_member']:
- interface = wg['intf']
- bridge = wg['is_bridge_member']
- raise ConfigError(f'Interface "{interface}" can not be deleted as it belongs to bridge "{bridge}"!')
+ raise ConfigError((
+ f'Cannot delete interface "{wg["intf"]}" as it is a member '
+ f'of bridge "{wg["is_bridge_member"]}"!'))
return None
@@ -220,25 +218,24 @@ def verify(wg):
'"run generate wireguard [keypair|named-keypairs]"')
if not wg['address']:
- raise ConfigError(f'IP address required for interface "{interface}"!')
+ raise ConfigError(f'IP address required for interface "{wg["intf"]}"!')
if not wg['peer']:
- raise ConfigError(f'Peer required for interface "{interface}"!')
+ raise ConfigError(f'Peer required for interface "{wg["intf"]}"!')
# run checks on individual configured WireGuard peer
for peer in wg['peer']:
- peer_name = peer['name']
if not peer['allowed-ips']:
- raise ConfigError(f'Peer allowed-ips required for peer "{peer_name}"!')
+ raise ConfigError(f'Peer allowed-ips required for peer "{peer["name"]}"!')
if not peer['pubkey']:
- raise ConfigError(f'Peer public-key required for peer "{peer_name}"!')
+ raise ConfigError(f'Peer public-key required for peer "{peer["name"]}"!')
if peer['address'] and not peer['port']:
- raise ConfigError(f'Peer "{peer_name}" port must be defined if address is defined!')
+ raise ConfigError(f'Peer "{peer["name"]}" port must be defined if address is defined!')
if not peer['address'] and peer['port']:
- raise ConfigError(f'Peer "{peer_name}" address must be defined if port is defined!')
+ raise ConfigError(f'Peer "{peer["name"]}" address must be defined if port is defined!')
def apply(wg):