From 8b72667f4d1944e83ffd869ee7e0fca79108eb13 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Fri, 25 Aug 2023 15:20:07 +0000 Subject: [PATCH] zones: Machine.RemoveWireguardKeys() Signed-off-by: Alejandro Mery --- pkg/zones/machine_rings.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/zones/machine_rings.go b/pkg/zones/machine_rings.go index 593e7d3..f62aa5a 100644 --- a/pkg/zones/machine_rings.go +++ b/pkg/zones/machine_rings.go @@ -105,6 +105,28 @@ func (m *Machine) WriteWireguardKeys(ring int) error { return nil } +// RemoveWireguardKeys deletes wgN.key and wgN.pub from +// the machine's config directory +func (m *Machine) RemoveWireguardKeys(ring int) error { + var err error + + err = m.RemoveFile("wg%v.pub", ring) + switch { + case os.IsNotExist(err): + // ignore + case err != nil: + return err + } + + err = m.RemoveFile("wg%v.key", ring) + if os.IsNotExist(err) { + // ignore + err = nil + } + + return err +} + // GetWireguardConfig reads a wgN.conf file func (m *Machine) GetWireguardConfig(ring int) (*wireguard.Config, error) { data, err := m.ReadFile("wg%v.conf", ring)