jpictl/dns: introduce add command to register new machines
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -2,9 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/netip"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"darvaza.org/core"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"git.jpi.io/amery/jpictl/pkg/cluster"
|
||||
@@ -149,10 +151,43 @@ var dnsShowCmd = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var dnsAddCmd = &cobra.Command{
|
||||
Use: "add <name> <address..>",
|
||||
Short: "dns add registers a new machine on the public DNS",
|
||||
Args: cobra.MinimumNArgs(2),
|
||||
PreRun: setVerbosity,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
var addrs []netip.Addr
|
||||
|
||||
for _, s := range args[1:] {
|
||||
addr, err := core.ParseAddr(s)
|
||||
switch {
|
||||
case err != nil:
|
||||
return core.Wrap(err, s)
|
||||
case !addr.IsValid(), addr.IsUnspecified(), addr.IsPrivate(), addr.IsMulticast():
|
||||
return core.Wrap(core.ErrInvalid, s)
|
||||
default:
|
||||
addrs = append(addrs, addr)
|
||||
}
|
||||
}
|
||||
|
||||
mgr, err := newDNSManagerCommand(cmd, true, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), DNSSyncTimeout)
|
||||
defer cancel()
|
||||
|
||||
return mgr.Add(ctx, args[0], addrs...)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(dnsCmd)
|
||||
|
||||
dnsCmd.AddCommand(dnsWriteCmd)
|
||||
dnsCmd.AddCommand(dnsSyncCmd)
|
||||
dnsCmd.AddCommand(dnsShowCmd)
|
||||
dnsCmd.AddCommand(dnsAddCmd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user