From 204370894924cf099d62781d88f4ad846c4c5830 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Fri, 25 Aug 2023 21:14:47 +0000 Subject: [PATCH] zones: Zones.WriteWireguardKeys() and Zone.WriteWireguardKeys() Signed-off-by: Alejandro Mery --- pkg/zones/zone_rings.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/zones/zone_rings.go b/pkg/zones/zone_rings.go index bde3b7a..4bd2e3b 100644 --- a/pkg/zones/zone_rings.go +++ b/pkg/zones/zone_rings.go @@ -1,5 +1,7 @@ package zones +import "os" + // PruneWireguardConfig removes wgN.conf files of machines with // the corresponding ring disabled. func (z *Zone) PruneWireguardConfig(ring int) error { @@ -16,6 +18,23 @@ func (z *Zone) PruneWireguardConfig(ring int) error { return err } +// WriteWireguardKeys rewrites all wgN.{key,pub} files on this zone +func (z *Zone) WriteWireguardKeys(ring int) error { + var err error + + z.ForEachMachine(func(p *Machine) bool { + err = p.WriteWireguardKeys(ring) + if os.IsNotExist(err) { + // ignore + err = nil + } + + return err != nil + }) + + return err +} + // PruneWireguardConfig removes wgN.conf files of machines with // the corresponding ring disabled on all zones func (m *Zones) PruneWireguardConfig(ring int) error { @@ -28,3 +47,15 @@ func (m *Zones) PruneWireguardConfig(ring int) error { return err } + +// WriteWireguardKeys rewrites all wgN.{key,pub} files +func (m *Zones) WriteWireguardKeys(ring int) error { + var err error + + m.ForEachZone(func(z *Zone) bool { + err = z.WriteWireguardKeys(ring) + return err != nil + }) + + return err +}