From a60f9c990cdf6c58905e3560f7bc34666e0b17b5 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Mon, 3 Jun 2024 09:40:47 +0200 Subject: [PATCH 1/2] change config generation --- src/db/models/device.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/db/models/device.rs b/src/db/models/device.rs index f21751e8e..435aecefc 100644 --- a/src/db/models/device.rs +++ b/src/db/models/device.rs @@ -366,12 +366,21 @@ impl Device { } None => String::new(), }; - let allowed_ips = network - .allowed_ips - .iter() - .map(IpNetwork::to_string) - .collect::>() - .join(","); + + let allowed_ips: String = if network.allowed_ips.is_empty() { + String::new() + } else { + format!( + "AllowedIPs = {}\n", + network + .allowed_ips + .iter() + .map(IpNetwork::to_string) + .collect::>() + .join(",") + ) + }; + format!( "[Interface]\n\ PrivateKey = YOUR_PRIVATE_KEY\n\ @@ -380,7 +389,7 @@ impl Device { \n\ [Peer]\n\ PublicKey = {}\n\ - AllowedIPs = {allowed_ips}\n\ + {allowed_ips}\ Endpoint = {}:{}\n\ PersistentKeepalive = 300", wireguard_network_device.wireguard_ip, network.pubkey, network.endpoint, network.port, From c97ff86906acf121890662a5991a1fa96c281a26 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:05:03 +0200 Subject: [PATCH 2/2] remove unnecessary type --- src/db/models/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/models/device.rs b/src/db/models/device.rs index 435aecefc..62583415e 100644 --- a/src/db/models/device.rs +++ b/src/db/models/device.rs @@ -367,7 +367,7 @@ impl Device { None => String::new(), }; - let allowed_ips: String = if network.allowed_ips.is_empty() { + let allowed_ips = if network.allowed_ips.is_empty() { String::new() } else { format!(