mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-11-10 08:20:35 +08:00
HEXONET: minor refactoring (#2255)
Co-authored-by: Asif Nawaz <asif.nawaz@centralnic.com>
This commit is contained in:
parent
bded57b375
commit
f17b34a513
2 changed files with 18 additions and 35 deletions
|
|
@ -1,7 +1,5 @@
|
||||||
package hexonet
|
package hexonet
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
// EnsureZoneExists returns an error
|
// EnsureZoneExists returns an error
|
||||||
// * if access to dnszone is not allowed (not authorized) or
|
// * if access to dnszone is not allowed (not authorized) or
|
||||||
// * if it doesn't exist and creating it fails
|
// * 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)
|
return nil, n.GetHXApiError("Error while QueryDNSZoneList", "Basic", &r)
|
||||||
}
|
}
|
||||||
zoneColumn := r.GetColumn("DNSZONE")
|
zoneColumn := r.GetColumn("DNSZONE")
|
||||||
if zoneColumn == nil {
|
if zoneColumn != nil {
|
||||||
return nil, fmt.Errorf("failed getting DNSZONE BASIC column")
|
//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
|
return zones, nil
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package hexonet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -11,7 +10,6 @@ import (
|
||||||
"github.com/StackExchange/dnscontrol/v3/models"
|
"github.com/StackExchange/dnscontrol/v3/models"
|
||||||
"github.com/StackExchange/dnscontrol/v3/pkg/diff"
|
"github.com/StackExchange/dnscontrol/v3/pkg/diff"
|
||||||
"github.com/StackExchange/dnscontrol/v3/pkg/diff2"
|
"github.com/StackExchange/dnscontrol/v3/pkg/diff2"
|
||||||
"github.com/StackExchange/dnscontrol/v3/pkg/printer"
|
|
||||||
"github.com/StackExchange/dnscontrol/v3/pkg/txtutil"
|
"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.
|
// GetDomainCorrections gathers correctios that would bring n to match dc.
|
||||||
func (n *HXClient) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
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)
|
actual, err := n.GetZoneRecords(dc.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -150,7 +151,9 @@ func toRecord(r *HXRecord, origin string) *models.RecordConfig {
|
||||||
|
|
||||||
switch rtype := r.Type; rtype {
|
switch rtype := r.Type; rtype {
|
||||||
case "TXT":
|
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":
|
case "MX":
|
||||||
if err := rc.SetTargetMX(uint16(r.Priority), r.Answer); err != nil {
|
if err := rc.SetTargetMX(uint16(r.Priority), r.Answer); err != nil {
|
||||||
panic(fmt.Errorf("unparsable MX record received from hexonet api: %w", err))
|
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
|
return rc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *HXClient) showCommand(cmd map[string]string) error {
|
// func (n *HXClient) showCommand(cmd map[string]string) error {
|
||||||
b, err := json.MarshalIndent(cmd, "", " ")
|
// b, err := json.MarshalIndent(cmd, "", " ")
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return fmt.Errorf("error: %w", err)
|
// return fmt.Errorf("error: %w", err)
|
||||||
}
|
// }
|
||||||
printer.Printf(string(b))
|
// printer.Printf(string(b))
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
|
|
||||||
func (n *HXClient) updateZoneBy(params map[string]interface{}, domain string) error {
|
func (n *HXClient) updateZoneBy(params map[string]interface{}, domain string) error {
|
||||||
zone := domain + "."
|
zone := domain + "."
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue