mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
HEXONET: Implement get-zones, fix module problem (#898)
* VULTR: Update govultr to v1.0.0 (fixes #892) (#897) * go get -u github.com/hexonet/go-sdk * Fix HEXONET providers.json entry * providers.json: json commma * providers.json: fmtjson * HEXONET: Implement get-zones. Fix tests and docs. * fixup! * Update azure test failures * Move version info into its own package * Use new version system
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
package hexonet
|
||||
|
||||
import "fmt"
|
||||
|
||||
//EnsureDomainExists returns an error
|
||||
// * if access to dnszone is not allowed (not authorized) or
|
||||
// * if it doesn't exist and creating it fails
|
||||
func (n *HXClient) EnsureDomainExists(domain string) error {
|
||||
r := n.client.Request(map[string]string{
|
||||
r := n.client.Request(map[string]interface{}{
|
||||
"COMMAND": "StatusDNSZone",
|
||||
"DNSZONE": domain + ".",
|
||||
})
|
||||
code := r.GetCode()
|
||||
if code == 545 {
|
||||
r = n.client.Request(map[string]string{
|
||||
r = n.client.Request(map[string]interface{}{
|
||||
"COMMAND": "CreateDNSZone",
|
||||
"DNSZONE": domain + ".",
|
||||
})
|
||||
@@ -24,3 +26,44 @@ func (n *HXClient) EnsureDomainExists(domain string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListZones lists all the
|
||||
func (n *HXClient) ListZones() ([]string, error) {
|
||||
var zones []string
|
||||
|
||||
// Basic
|
||||
|
||||
rs := n.client.RequestAllResponsePages(map[string]string{
|
||||
"COMMAND": "QueryDNSZoneList",
|
||||
})
|
||||
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 BASIC column")
|
||||
}
|
||||
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
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/version"
|
||||
"github.com/StackExchange/dnscontrol/v3/providers"
|
||||
hxcl "github.com/hexonet/go-sdk/apiclient"
|
||||
)
|
||||
@@ -36,6 +37,7 @@ func newProvider(conf map[string]string) (*HXClient, error) {
|
||||
api := &HXClient{
|
||||
client: hxcl.NewAPIClient(),
|
||||
}
|
||||
api.client.SetUserAgent("DNSControl", version.VersionString())
|
||||
api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"]
|
||||
if conf["debugmode"] == "1" {
|
||||
api.client.EnableDebugMode()
|
||||
|
@@ -41,7 +41,7 @@ func (n *HXClient) GetNameservers(domain string) ([]*models.Nameserver, error) {
|
||||
}
|
||||
|
||||
func (n *HXClient) getNameserversRaw(domain string) ([]string, error) {
|
||||
r := n.client.Request(map[string]string{
|
||||
r := n.client.Request(map[string]interface{}{
|
||||
"COMMAND": "StatusDomain",
|
||||
"DOMAIN": domain,
|
||||
})
|
||||
@@ -87,7 +87,7 @@ func (n *HXClient) GetRegistrarCorrections(dc *models.DomainConfig) ([]*models.C
|
||||
|
||||
func (n *HXClient) updateNameservers(ns []string, domain string) func() error {
|
||||
return func() error {
|
||||
cmd := map[string]string{
|
||||
cmd := map[string]interface{}{
|
||||
"COMMAND": "ModifyDomain",
|
||||
"DOMAIN": domain,
|
||||
}
|
||||
|
@@ -37,30 +37,34 @@ type HXRecord struct {
|
||||
|
||||
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
|
||||
func (n *HXClient) GetZoneRecords(domain string) (models.Records, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
// This enables the get-zones subcommand.
|
||||
// Implement this by extracting the code from GetDomainCorrections into
|
||||
// a single function. For most providers this should be relatively easy.
|
||||
}
|
||||
|
||||
// GetDomainCorrections gathers correctios that would bring n to match dc.
|
||||
func (n *HXClient) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
||||
dc.Punycode()
|
||||
records, err := n.getRecords(dc.Name)
|
||||
records, err := n.getRecords(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
actual := make([]*models.RecordConfig, len(records))
|
||||
for i, r := range records {
|
||||
actual[i] = toRecord(r, dc.Name)
|
||||
actual[i] = toRecord(r, domain)
|
||||
}
|
||||
|
||||
for _, rec := range dc.Records {
|
||||
for _, rec := range actual {
|
||||
if rec.Type == "ALIAS" {
|
||||
return nil, fmt.Errorf("we support realtime ALIAS RR over our X-DNS service, please get in touch with us")
|
||||
}
|
||||
}
|
||||
|
||||
return actual, nil
|
||||
|
||||
}
|
||||
|
||||
// GetDomainCorrections gathers correctios that would bring n to match dc.
|
||||
func (n *HXClient) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
||||
dc.Punycode()
|
||||
|
||||
actual, err := n.GetZoneRecords(dc.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//checkNSModifications(dc)
|
||||
|
||||
// Normalize
|
||||
@@ -77,7 +81,7 @@ func (n *HXClient) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Corr
|
||||
buf := &bytes.Buffer{}
|
||||
// Print a list of changes. Generate an actual change that is the zone
|
||||
changes := false
|
||||
params := map[string]string{}
|
||||
params := map[string]interface{}{}
|
||||
delrridx := 0
|
||||
addrridx := 0
|
||||
for _, cre := range create {
|
||||
@@ -161,9 +165,9 @@ func (n *HXClient) showCommand(cmd map[string]string) {
|
||||
fmt.Print(string(b))
|
||||
}
|
||||
|
||||
func (n *HXClient) updateZoneBy(params map[string]string, domain string) error {
|
||||
func (n *HXClient) updateZoneBy(params map[string]interface{}, domain string) error {
|
||||
zone := domain + "."
|
||||
cmd := map[string]string{
|
||||
cmd := map[string]interface{}{
|
||||
"COMMAND": "UpdateDNSZone",
|
||||
"DNSZONE": zone,
|
||||
"INCSERIAL": "1",
|
||||
@@ -182,7 +186,7 @@ func (n *HXClient) updateZoneBy(params map[string]string, domain string) error {
|
||||
func (n *HXClient) getRecords(domain string) ([]*HXRecord, error) {
|
||||
var records []*HXRecord
|
||||
zone := domain + "."
|
||||
cmd := map[string]string{
|
||||
cmd := map[string]interface{}{
|
||||
"COMMAND": "QueryDNSZoneRRList",
|
||||
"DNSZONE": zone,
|
||||
"SHORT": "1",
|
||||
|
Reference in New Issue
Block a user