Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-25 17:40:42 +00:00
parent 3662fc7510
commit 09678d8eb8
4 changed files with 121 additions and 3 deletions
+50 -1
View File
@@ -1,6 +1,45 @@
package zones
import "os"
import (
"os"
"git.jpi.io/amery/jpictl/pkg/wireguard"
)
type Ring struct {
Ring int
}
func (*Ring) ExportConfig(_ int) (*wireguard.Config, error) {
return nil, nil
}
func (*Zone) GetRing(_ int) (*Ring, error) {
return &Ring{}, nil
}
// SyncWireguardConfig updates all wgN.conf files for the specified
// ring
func (z *Zone) SyncWireguardConfig(ring int) error {
err := z.PruneWireguardConfig(ring)
if err != nil {
return err
}
r, err := z.GetRing(ring)
if err != nil {
return err
}
z.ForEachMachine(func(p *Machine) bool {
if _, ok := p.getRingInfo(ring); ok {
err = p.writeWireguardRing(r)
}
return err != nil
})
return err
}
// PruneWireguardConfig removes wgN.conf files of machines with
// the corresponding ring disabled.
@@ -59,3 +98,13 @@ func (m *Zones) WriteWireguardKeys(ring int) error {
return err
}
// SyncWireguardConfig updates all wgN.conf files for the specified
// ring
func (m *Zones) SyncWireguardConfig(ring int) error {
err := m.PruneWireguardConfig(ring)
if err != nil {
return err
}
}