Compare commits
18 Commits
v0.6.9
..
0ff17abd59
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ff17abd59 | |||
| a742bad084 | |||
| 629b6ee74f | |||
| 884b11d1f9 | |||
| 5bbe15ef24 | |||
| fd1c57d377 | |||
| 2fd5947f1b | |||
| 14b3d91191 | |||
| abe3005769 | |||
| 9ab7594bcc | |||
| 07d4f462a3 | |||
| 142ea00577 | |||
| 052f89152c | |||
| 557f156579 | |||
| e857ff7456 | |||
| 9da49f2d86 | |||
| 356322bc94 | |||
| 7dac96f474 |
@@ -2,9 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"darvaza.org/core"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"git.jpi.io/amery/jpictl/pkg/cluster"
|
"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() {
|
func init() {
|
||||||
rootCmd.AddCommand(dnsCmd)
|
rootCmd.AddCommand(dnsCmd)
|
||||||
|
|
||||||
dnsCmd.AddCommand(dnsWriteCmd)
|
dnsCmd.AddCommand(dnsWriteCmd)
|
||||||
dnsCmd.AddCommand(dnsSyncCmd)
|
dnsCmd.AddCommand(dnsSyncCmd)
|
||||||
dnsCmd.AddCommand(dnsShowCmd)
|
dnsCmd.AddCommand(dnsShowCmd)
|
||||||
|
dnsCmd.AddCommand(dnsAddCmd)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package cluster
|
package cluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
fs "github.com/hack-pad/hackpadfs"
|
fs "github.com/hack-pad/hackpadfs"
|
||||||
)
|
)
|
||||||
@@ -40,6 +43,21 @@ func (m *Cluster) openWriter(name string, flags int, args ...any) (io.WriteClose
|
|||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveFile deletes a file from the cluster's config directory
|
||||||
|
func (m *Cluster) RemoveFile(name string, args ...any) error {
|
||||||
|
if len(args) > 0 {
|
||||||
|
name = fmt.Sprintf(name, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := fs.Remove(m.dir, name)
|
||||||
|
switch {
|
||||||
|
case os.IsNotExist(err):
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ReadFile reads a file from the cluster's config directory
|
// ReadFile reads a file from the cluster's config directory
|
||||||
func (m *Cluster) ReadFile(name string, args ...any) ([]byte, error) {
|
func (m *Cluster) ReadFile(name string, args ...any) ([]byte, error) {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
@@ -48,3 +66,41 @@ func (m *Cluster) ReadFile(name string, args ...any) ([]byte, error) {
|
|||||||
|
|
||||||
return fs.ReadFile(m.dir, name)
|
return fs.ReadFile(m.dir, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadLines reads a file from the cluster's config directory,
|
||||||
|
// split by lines, trimmed, and accepting `#` to comment lines out.
|
||||||
|
func (m *Cluster) ReadLines(name string, args ...any) ([]string, error) {
|
||||||
|
var out []string
|
||||||
|
|
||||||
|
data, err := m.ReadFile(name, args...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sc := bufio.NewScanner(bytes.NewReader(data))
|
||||||
|
for sc.Scan() {
|
||||||
|
s := strings.TrimSpace(sc.Text())
|
||||||
|
switch {
|
||||||
|
case s == "", strings.HasPrefix(s, "#"):
|
||||||
|
// ignore
|
||||||
|
default:
|
||||||
|
// accepted
|
||||||
|
out = append(out, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteStringFile writes the given content to a file on the machine's config directory
|
||||||
|
func (m *Cluster) WriteStringFile(value string, name string, args ...any) error {
|
||||||
|
f, err := m.CreateTruncFile(name, args...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
buf := bytes.NewBufferString(value)
|
||||||
|
_, err = buf.WriteTo(f)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package cluster
|
package cluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -43,16 +42,9 @@ func (m *Machine) openWriter(name string, flags int, args ...any) (io.WriteClose
|
|||||||
|
|
||||||
// RemoveFile deletes a file from the machine's config directory
|
// RemoveFile deletes a file from the machine's config directory
|
||||||
func (m *Machine) RemoveFile(name string, args ...any) error {
|
func (m *Machine) RemoveFile(name string, args ...any) error {
|
||||||
base := m.zone.zones.dir
|
|
||||||
fullName := m.getFilename(name, args...)
|
fullName := m.getFilename(name, args...)
|
||||||
err := fs.Remove(base, fullName)
|
|
||||||
|
|
||||||
switch {
|
return m.zone.zones.RemoveFile(fullName)
|
||||||
case os.IsNotExist(err):
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFile reads a file from the machine's config directory
|
// ReadFile reads a file from the machine's config directory
|
||||||
@@ -65,15 +57,9 @@ func (m *Machine) ReadFile(name string, args ...any) ([]byte, error) {
|
|||||||
|
|
||||||
// WriteStringFile writes the given content to a file on the machine's config directory
|
// WriteStringFile writes the given content to a file on the machine's config directory
|
||||||
func (m *Machine) WriteStringFile(value string, name string, args ...any) error {
|
func (m *Machine) WriteStringFile(value string, name string, args ...any) error {
|
||||||
f, err := m.CreateTruncFile(name, args...)
|
fullName := m.getFilename(name, args...)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
buf := bytes.NewBufferString(value)
|
return m.zone.zones.WriteStringFile(value, fullName)
|
||||||
_, err = buf.WriteTo(f)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) getFilename(name string, args ...any) string {
|
func (m *Machine) getFilename(name string, args ...any) string {
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ func (m *Cluster) initRegions(_ *ScanOptions) error {
|
|||||||
|
|
||||||
// first regions defined by zones
|
// first regions defined by zones
|
||||||
m.ForEachZone(func(z *Zone) bool {
|
m.ForEachZone(func(z *Zone) bool {
|
||||||
|
SortRegions(z.Regions)
|
||||||
for _, region := range z.Regions {
|
for _, region := range z.Regions {
|
||||||
regions[region] = append(regions[region], z)
|
regions[region] = append(regions[region], z)
|
||||||
}
|
}
|
||||||
@@ -74,6 +75,7 @@ func (m *Cluster) initRegions(_ *ScanOptions) error {
|
|||||||
m.finishRegion(r)
|
m.finishRegion(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.sortRegions()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package cluster
|
||||||
|
|
||||||
|
import "sort"
|
||||||
|
|
||||||
|
// SortRegions sorts regions. first by length those 3-character
|
||||||
|
// or shorter, and then by length. It's mostly aimed at
|
||||||
|
// supporting ISO-3166 order
|
||||||
|
func SortRegions(regions []string) []string {
|
||||||
|
sort.Slice(regions, func(i, j int) bool {
|
||||||
|
r1, r2 := regions[i], regions[j]
|
||||||
|
return regionLess(r1, r2)
|
||||||
|
})
|
||||||
|
|
||||||
|
return regions
|
||||||
|
}
|
||||||
|
|
||||||
|
func regionLess(r1, r2 string) bool {
|
||||||
|
switch {
|
||||||
|
case len(r1) < 4:
|
||||||
|
switch {
|
||||||
|
case len(r1) < len(r2):
|
||||||
|
return true
|
||||||
|
case len(r1) > len(r2):
|
||||||
|
return false
|
||||||
|
default:
|
||||||
|
return r1 < r2
|
||||||
|
}
|
||||||
|
case len(r2) < 4:
|
||||||
|
return false
|
||||||
|
default:
|
||||||
|
return r1 < r2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Cluster) sortRegions() {
|
||||||
|
sort.Slice(m.Regions, func(i, j int) bool {
|
||||||
|
r1 := m.Regions[i].Name
|
||||||
|
r2 := m.Regions[j].Name
|
||||||
|
return regionLess(r1, r2)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package dns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/netip"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"darvaza.org/core"
|
||||||
|
"github.com/libdns/libdns"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Add adds a machine to the DNS records
|
||||||
|
func (mgr *Manager) Add(ctx context.Context, name string, addrs ...netip.Addr) error {
|
||||||
|
// TODO: validate name
|
||||||
|
|
||||||
|
cur, err := mgr.GetRecords(ctx, name)
|
||||||
|
if err != nil {
|
||||||
|
return core.Wrap(err, "GetRecords")
|
||||||
|
}
|
||||||
|
|
||||||
|
// merge []SyncAddr for name
|
||||||
|
s := mgr.asSyncRecordsMap(cur)[name+mgr.suffix]
|
||||||
|
for _, addr := range addrs {
|
||||||
|
s = AppendSyncAddr(s, addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return mgr.addSyncAddr(ctx, name, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mgr *Manager) addSyncAddr(ctx context.Context, name string, s []SyncAddr) error {
|
||||||
|
var recs []libdns.Record
|
||||||
|
|
||||||
|
for _, a := range s {
|
||||||
|
recs = append(recs, libdns.Record{
|
||||||
|
ID: a.ID,
|
||||||
|
Name: name + mgr.suffix,
|
||||||
|
Type: core.IIf(a.Addr.Is6(), "AAAA", "A"),
|
||||||
|
TTL: time.Second,
|
||||||
|
Value: a.Addr.String(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
SortRecords(recs)
|
||||||
|
err := writeRecords(recs, os.Stdout)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = mgr.p.SetRecords(ctx, mgr.domain, recs)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppendSyncAddr appends a [netip.Addr] to a [SyncAddr] slice
|
||||||
|
// if the address is new.
|
||||||
|
func AppendSyncAddr(s []SyncAddr, addr netip.Addr) []SyncAddr {
|
||||||
|
for _, se := range s {
|
||||||
|
if se.Addr.Compare(addr) == 0 {
|
||||||
|
// found
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s = append(s, SyncAddr{
|
||||||
|
Addr: addr,
|
||||||
|
TTL: time.Second,
|
||||||
|
})
|
||||||
|
return s
|
||||||
|
}
|
||||||
+51
-17
@@ -6,10 +6,13 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"darvaza.org/core"
|
"darvaza.org/core"
|
||||||
"github.com/libdns/libdns"
|
"github.com/libdns/libdns"
|
||||||
|
|
||||||
|
"git.jpi.io/amery/jpictl/pkg/cluster"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (mgr *Manager) fqdn(name string) string {
|
func (mgr *Manager) fqdn(name string) string {
|
||||||
@@ -38,30 +41,51 @@ func SortAddrRecords(s []AddrRecord) []AddrRecord {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// SortRegions sorts regions. first by length those 3-character
|
// SortRecords sorts a slice of [libdns.Record], by Name, Type and Value
|
||||||
// or shorter, and then by length. It's mostly aimed at
|
func SortRecords(s []libdns.Record) []libdns.Record {
|
||||||
// supporting ISO-3166 order
|
sort.Slice(s, func(i, j int) bool {
|
||||||
func SortRegions(regions []string) []string {
|
return lessRecord(s[i], s[j])
|
||||||
sort.Slice(regions, func(i, j int) bool {
|
})
|
||||||
r1, r2 := regions[i], regions[j]
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func lessRecord(a, b libdns.Record) bool {
|
||||||
|
aName := strings.ToLower(a.Name)
|
||||||
|
bName := strings.ToLower(b.Name)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case len(r1) < 4:
|
case aName < bName:
|
||||||
switch {
|
|
||||||
case len(r1) < len(r2):
|
|
||||||
return true
|
return true
|
||||||
case len(r1) > len(r2):
|
case aName > bName:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
aType := strings.ToUpper(a.Type)
|
||||||
|
bType := strings.ToUpper(b.Type)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case aType < bType:
|
||||||
|
return true
|
||||||
|
case aType > bType:
|
||||||
|
return false
|
||||||
|
case aType == "A", aType == "AAAA":
|
||||||
|
// IP Addresses
|
||||||
|
var aa, ba netip.Addr
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case aa.UnmarshalText([]byte(a.Value)) != nil:
|
||||||
|
// bad address on a
|
||||||
|
return true
|
||||||
|
case ba.UnmarshalText([]byte(b.Value)) != nil:
|
||||||
|
// bad address on b
|
||||||
return false
|
return false
|
||||||
default:
|
default:
|
||||||
return r1 < r2
|
return aa.Less(ba)
|
||||||
}
|
}
|
||||||
case len(r2) < 4:
|
|
||||||
return false
|
|
||||||
default:
|
default:
|
||||||
return r1 < r2
|
// text
|
||||||
|
return a.Value < b.Value
|
||||||
}
|
}
|
||||||
})
|
|
||||||
return regions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddrRecord represents an A or AAAA record
|
// AddrRecord represents an A or AAAA record
|
||||||
@@ -124,7 +148,17 @@ func (mgr *Manager) genRegionsSorted() []string {
|
|||||||
regions = append(regions, name)
|
regions = append(regions, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return SortRegions(regions)
|
return cluster.SortRegions(regions)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mgr *Manager) genZonesSorted() []string {
|
||||||
|
zones := make([]string, 0, len(mgr.zones))
|
||||||
|
for name := range mgr.zones {
|
||||||
|
zones = append(zones, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(zones)
|
||||||
|
return zones
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mgr *Manager) genAllAddrRecords() []AddrRecord {
|
func (mgr *Manager) genAllAddrRecords() []AddrRecord {
|
||||||
|
|||||||
+38
-9
@@ -1,11 +1,15 @@
|
|||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"darvaza.org/core"
|
"darvaza.org/core"
|
||||||
|
"github.com/libdns/libdns"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Show shows current DNS entries
|
// Show shows current DNS entries
|
||||||
@@ -15,15 +19,40 @@ func (mgr *Manager) Show(ctx context.Context, names ...string) error {
|
|||||||
return core.Wrap(err, "GetRecords")
|
return core.Wrap(err, "GetRecords")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rr := range recs {
|
SortRecords(recs)
|
||||||
_, _ = fmt.Printf("%s\t%v\tIN\t%s\t%s\t; %s\n",
|
return writeRecords(recs, os.Stdout)
|
||||||
rr.Name,
|
|
||||||
int(rr.TTL/time.Second),
|
|
||||||
rr.Type,
|
|
||||||
rr.Value,
|
|
||||||
rr.ID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _ = fmt.Printf("; %v records\n", len(recs))
|
func writeRecords(recs []libdns.Record, w io.Writer) error {
|
||||||
return nil
|
var buf bytes.Buffer
|
||||||
|
|
||||||
|
for _, rr := range recs {
|
||||||
|
_ = fmtRecord(&buf, rr)
|
||||||
|
_, _ = buf.WriteRune('\n')
|
||||||
|
}
|
||||||
|
_, _ = fmt.Fprintf(&buf, "; %v records\n", len(recs))
|
||||||
|
|
||||||
|
_, err := buf.WriteTo(w)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func fmtRecord(w io.Writer, rr libdns.Record) error {
|
||||||
|
ttl := int(rr.TTL / time.Second)
|
||||||
|
if ttl < 1 {
|
||||||
|
ttl = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := fmt.Fprintf(w, "%s\t%v\tIN\t%s\t%s",
|
||||||
|
rr.Name,
|
||||||
|
ttl,
|
||||||
|
rr.Type,
|
||||||
|
rr.Value)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
if rr.ID != "" {
|
||||||
|
_, err = fmt.Fprintf(w, "\t; %s", rr.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-4
@@ -54,7 +54,7 @@ func (mgr *Manager) GetSyncRecords(ctx context.Context) ([]SyncAddrRecord, error
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return mgr.filteredSyncRecords(recs)
|
return mgr.asSyncRecords(recs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsSyncAddr converts a A or AAAA [libdns.Record] into a [SyncAddr]
|
// AsSyncAddr converts a A or AAAA [libdns.Record] into a [SyncAddr]
|
||||||
@@ -89,9 +89,9 @@ func (mgr *Manager) AsSyncAddr(rr libdns.Record) (SyncAddr, bool, error) {
|
|||||||
return out, true, nil
|
return out, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mgr *Manager) filteredSyncRecords(recs []libdns.Record) ([]SyncAddrRecord, error) {
|
func (mgr *Manager) asSyncRecordsMap(recs []libdns.Record) map[string][]SyncAddr {
|
||||||
// filter and convert
|
// filter and convert
|
||||||
cache := make(map[string][]SyncAddr)
|
out := make(map[string][]SyncAddr)
|
||||||
for _, rr := range recs {
|
for _, rr := range recs {
|
||||||
addr, ok, err := mgr.AsSyncAddr(rr)
|
addr, ok, err := mgr.AsSyncAddr(rr)
|
||||||
switch {
|
switch {
|
||||||
@@ -106,9 +106,14 @@ func (mgr *Manager) filteredSyncRecords(recs []libdns.Record) ([]SyncAddrRecord,
|
|||||||
Print()
|
Print()
|
||||||
case ok:
|
case ok:
|
||||||
// store
|
// store
|
||||||
cache[rr.Name] = append(cache[rr.Name], addr)
|
out[rr.Name] = append(out[rr.Name], addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mgr *Manager) asSyncRecords(recs []libdns.Record) ([]SyncAddrRecord, error) {
|
||||||
|
cache := mgr.asSyncRecordsMap(recs)
|
||||||
|
|
||||||
// prepare records
|
// prepare records
|
||||||
out := make([]SyncAddrRecord, len(cache))
|
out := make([]SyncAddrRecord, len(cache))
|
||||||
|
|||||||
+3
-2
@@ -14,12 +14,13 @@ func (mgr *Manager) WriteTo(w io.Writer) (int64, error) {
|
|||||||
cache := make(map[string][]netip.Addr)
|
cache := make(map[string][]netip.Addr)
|
||||||
|
|
||||||
// zones
|
// zones
|
||||||
for _, z := range mgr.zones {
|
for _, zoneName := range mgr.genZonesSorted() {
|
||||||
|
z := mgr.zones[zoneName]
|
||||||
|
|
||||||
mgr.writeZoneHosts(&buf, z)
|
mgr.writeZoneHosts(&buf, z)
|
||||||
|
|
||||||
// zone alias
|
// zone alias
|
||||||
addrs := mgr.genZoneAddresses(z)
|
addrs := mgr.genZoneAddresses(z)
|
||||||
zoneName := z.Name
|
|
||||||
|
|
||||||
rr := AddrRecord{
|
rr := AddrRecord{
|
||||||
Name: mgr.fqdn(zoneName + mgr.suffix),
|
Name: mgr.fqdn(zoneName + mgr.suffix),
|
||||||
|
|||||||
@@ -183,20 +183,14 @@ type KeyPair struct {
|
|||||||
// Validate checks the PublicKey matches the PrivateKey,
|
// Validate checks the PublicKey matches the PrivateKey,
|
||||||
// and sets the PublicKey if missing
|
// and sets the PublicKey if missing
|
||||||
func (kp *KeyPair) Validate() error {
|
func (kp *KeyPair) Validate() error {
|
||||||
keyLen := len(kp.PrivateKey)
|
|
||||||
pubLen := len(kp.PublicKey)
|
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case keyLen != PrivateKeySize:
|
case kp.PrivateKey.IsZero():
|
||||||
// bad private key
|
// no private key
|
||||||
return ErrInvalidPrivateKey
|
return ErrInvalidPrivateKey
|
||||||
case pubLen == 0:
|
case kp.PublicKey.IsZero():
|
||||||
// no public key, set it
|
// no public key, set it
|
||||||
kp.PublicKey = kp.PrivateKey.Public()
|
kp.PublicKey = kp.PrivateKey.Public()
|
||||||
return nil
|
return nil
|
||||||
case pubLen != PublicKeySize:
|
|
||||||
// bad public key
|
|
||||||
return ErrInvalidPublicKey
|
|
||||||
case !kp.PrivateKey.Public().Equal(kp.PublicKey):
|
case !kp.PrivateKey.Public().Equal(kp.PublicKey):
|
||||||
// wrong public key
|
// wrong public key
|
||||||
return ErrInvalidPublicKey
|
return ErrInvalidPublicKey
|
||||||
|
|||||||
Reference in New Issue
Block a user