Browse Source

jpictl: refactor dns command initialization

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/27/head
Alejandro Mery 1 year ago
parent
commit
c578990f8c
  1. 46
      cmd/jpictl/dns.go

46
cmd/jpictl/dns.go

@ -72,6 +72,29 @@ func populateDNSManager(mgr *dns.Manager, m *cluster.Cluster) error {
return err
}
// revive:disable:flag-parameter
func newDNSManagerCommand(_ *cobra.Command,
resolve bool, withCredentials bool) (*dns.Manager, error) {
// revive:enable:flag-parameter
var cred dns.Provider
if withCredentials {
var err error
cred, err = dns.DefaultDNSProvider()
if err != nil {
return nil, err
}
}
m, err := cfg.LoadZones(resolve)
if err != nil {
return nil, err
}
return newDNSManager(m, cred)
}
// Command
var dnsCmd = &cobra.Command{
Use: "dns",
@ -81,13 +104,8 @@ var dnsWriteCmd = &cobra.Command{
Use: "write",
Short: "dns write generates public DNS records",
PreRun: setVerbosity,
RunE: func(_ *cobra.Command, _ []string) error {
m, err := cfg.LoadZones(true)
if err != nil {
return err
}
mgr, err := newDNSManager(m, nil)
RunE: func(cmd *cobra.Command, _ []string) error {
mgr, err := newDNSManagerCommand(cmd, true, false)
if err != nil {
return err
}
@ -101,18 +119,8 @@ var dnsSyncCmd = &cobra.Command{
Use: "sync",
Short: "dns sync updates public DNS records",
PreRun: setVerbosity,
RunE: func(_ *cobra.Command, _ []string) error {
cred, err := dns.DefaultDNSProvider()
if err != nil {
return err
}
m, err := cfg.LoadZones(true)
if err != nil {
return err
}
mgr, err := newDNSManager(m, cred)
RunE: func(cmd *cobra.Command, _ []string) error {
mgr, err := newDNSManagerCommand(cmd, true, true)
if err != nil {
return err
}

Loading…
Cancel
Save