Browse Source

jpictl: introduce `write` command rewriting all config files

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/1/head v0.4.5
Alejandro Mery 1 year ago
parent
commit
dfbb358187
  1. 23
      cmd/jpictl/write.go
  2. 33
      pkg/zones/sync.go

23
cmd/jpictl/write.go

@ -0,0 +1,23 @@
package main
import (
"github.com/spf13/cobra"
)
// Command
var writeCmd = &cobra.Command{
Use: "write",
Short: "rewrites all config files",
RunE: func(_ *cobra.Command, _ []string) error {
m, err := cfg.LoadZones()
if err != nil {
return err
}
return m.SyncAll()
},
}
func init() {
rootCmd.AddCommand(writeCmd)
}

33
pkg/zones/sync.go

@ -0,0 +1,33 @@
package zones
// SyncAll updates all config files
func (m *Zones) SyncAll() error {
for _, fn := range []func() error{
m.SyncAllWireguard,
} {
if err := fn(); err != nil {
return err
}
}
return nil
}
// SyncAllWireguard updates all wireguard config files
func (m *Zones) SyncAllWireguard() error {
var err error
for ring := 0; ring < RingsCount; ring++ {
err = m.PruneWireguardConfig(ring)
if err != nil {
return err
}
err = m.WriteWireguardKeys(ring)
if err != nil {
return err
}
}
return nil
}
Loading…
Cancel
Save