dns: refactor GetRecords() to allow commands other than sync
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
+6
-11
@@ -2,7 +2,6 @@ package dns
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/netip"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -48,18 +47,14 @@ func SortSyncAddrSlice(s []SyncAddr) []SyncAddr {
|
||||
return s
|
||||
}
|
||||
|
||||
// GetRecords pulls all the address records on DNS for our domain
|
||||
func (mgr *Manager) GetRecords(ctx context.Context) ([]SyncAddrRecord, error) {
|
||||
if mgr.p == nil {
|
||||
return nil, errors.New("dns provider not specified")
|
||||
}
|
||||
|
||||
recs, err := mgr.p.GetRecords(ctx, mgr.domain)
|
||||
// GetSyncRecords pulls all the address records on DNS for our domain
|
||||
func (mgr *Manager) GetSyncRecords(ctx context.Context) ([]SyncAddrRecord, error) {
|
||||
recs, err := mgr.GetRecords(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mgr.filteredRecords(recs)
|
||||
return mgr.filteredSyncRecords(recs)
|
||||
}
|
||||
|
||||
// AsSyncAddr converts a A or AAAA [libdns.Record] into a [SyncAddr]
|
||||
@@ -94,7 +89,7 @@ func (mgr *Manager) AsSyncAddr(rr libdns.Record) (SyncAddr, bool, error) {
|
||||
return out, true, nil
|
||||
}
|
||||
|
||||
func (mgr *Manager) filteredRecords(recs []libdns.Record) ([]SyncAddrRecord, error) {
|
||||
func (mgr *Manager) filteredSyncRecords(recs []libdns.Record) ([]SyncAddrRecord, error) {
|
||||
// filter and convert
|
||||
cache := make(map[string][]SyncAddr)
|
||||
for _, rr := range recs {
|
||||
@@ -137,7 +132,7 @@ func (mgr *Manager) filteredRecords(recs []libdns.Record) ([]SyncAddrRecord, err
|
||||
|
||||
// Sync updates all the address records on DNS for our domain
|
||||
func (mgr *Manager) Sync(ctx context.Context) error {
|
||||
current, err := mgr.GetRecords(ctx)
|
||||
current, err := mgr.GetSyncRecords(ctx)
|
||||
if err != nil {
|
||||
return core.Wrap(err, "GetRecords")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user