1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

HEXONET: minor refactoring (#2255)

Co-authored-by: Asif Nawaz <asif.nawaz@centralnic.com>
This commit is contained in:
Kai Schwarz
2023-03-31 13:47:42 +02:00
committed by GitHub
parent bded57b375
commit f17b34a513
2 changed files with 18 additions and 35 deletions

View File

@ -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

View File

@ -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 + "."