From f17b34a51320ef8024e675ae0b6b42ee6d25d0a5 Mon Sep 17 00:00:00 2001 From: Kai Schwarz Date: Fri, 31 Mar 2023 13:47:42 +0200 Subject: [PATCH] HEXONET: minor refactoring (#2255) Co-authored-by: Asif Nawaz --- providers/hexonet/domains.go | 26 +++----------------------- providers/hexonet/records.go | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/providers/hexonet/domains.go b/providers/hexonet/domains.go index 2dd22f06e..e83cc2308 100644 --- a/providers/hexonet/domains.go +++ b/providers/hexonet/domains.go @@ -1,7 +1,5 @@ package hexonet -import "fmt" - // EnsureZoneExists returns an error // * if access to dnszone is not allowed (not authorized) or // * if it doesn't exist and creating it fails @@ -41,28 +39,10 @@ func (n *HXClient) ListZones() ([]string, error) { return nil, n.GetHXApiError("Error while QueryDNSZoneList", "Basic", &r) } zoneColumn := r.GetColumn("DNSZONE") - if zoneColumn == nil { - return nil, fmt.Errorf("failed getting DNSZONE BASIC column") + if zoneColumn != nil { + //return nil, fmt.Errorf("failed getting DNSZONE BASIC column") + zones = append(zones, zoneColumn.GetData()...) } - zones = append(zones, zoneColumn.GetData()...) - } - - // Premium - - rs = n.client.RequestAllResponsePages(map[string]string{ - "COMMAND": "QueryDNSZoneList", - "PROPERTIES": "PREMIUMDNS", - "PREMIUMDNSCLASS": "*", - }) - for _, r := range rs { - if r.IsError() { - return nil, n.GetHXApiError("Error while QueryDNSZoneList", "Basic", &r) - } - zoneColumn := r.GetColumn("DNSZONE") - if zoneColumn == nil { - return nil, fmt.Errorf("failed getting DNSZONE PREMIUM column") - } - zones = append(zones, zoneColumn.GetData()...) } return zones, nil diff --git a/providers/hexonet/records.go b/providers/hexonet/records.go index a84560053..31dbd02a6 100644 --- a/providers/hexonet/records.go +++ b/providers/hexonet/records.go @@ -2,7 +2,6 @@ package hexonet import ( "bytes" - "encoding/json" "fmt" "regexp" "strconv" @@ -11,7 +10,6 @@ import ( "github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/pkg/diff" "github.com/StackExchange/dnscontrol/v3/pkg/diff2" - "github.com/StackExchange/dnscontrol/v3/pkg/printer" "github.com/StackExchange/dnscontrol/v3/pkg/txtutil" ) @@ -61,7 +59,10 @@ func (n *HXClient) GetZoneRecords(domain string) (models.Records, error) { // GetDomainCorrections gathers correctios that would bring n to match dc. func (n *HXClient) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) { - dc.Punycode() + err := dc.Punycode() + if err != nil { + return nil, err + } actual, err := n.GetZoneRecords(dc.Name) if err != nil { @@ -150,7 +151,9 @@ func toRecord(r *HXRecord, origin string) *models.RecordConfig { switch rtype := r.Type; rtype { case "TXT": - rc.SetTargetTXTs(decodeTxt(r.Answer)) + if err := rc.SetTargetTXTs(decodeTxt(r.Answer)); err != nil { + panic(fmt.Errorf("unparsable TXT record received from hexonet api: %w", err)) + } case "MX": if err := rc.SetTargetMX(uint16(r.Priority), r.Answer); err != nil { panic(fmt.Errorf("unparsable MX record received from hexonet api: %w", err)) @@ -167,14 +170,14 @@ func toRecord(r *HXRecord, origin string) *models.RecordConfig { return rc } -func (n *HXClient) showCommand(cmd map[string]string) error { - b, err := json.MarshalIndent(cmd, "", " ") - if err != nil { - return fmt.Errorf("error: %w", err) - } - printer.Printf(string(b)) - return nil -} +// func (n *HXClient) showCommand(cmd map[string]string) error { +// b, err := json.MarshalIndent(cmd, "", " ") +// if err != nil { +// return fmt.Errorf("error: %w", err) +// } +// printer.Printf(string(b)) +// return nil +// } func (n *HXClient) updateZoneBy(params map[string]interface{}, domain string) error { zone := domain + "."