mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
HEXONET: Update hexonet-sdk to v2.2.3+incompatible (#662)
* Update hexonet-sdk to v2.2.3+incompatible * Update vendor * Go mod tidy
This commit is contained in:
@@ -8,7 +8,7 @@ func (n *HXClient) EnsureDomainExists(domain string) error {
|
||||
"COMMAND": "StatusDNSZone",
|
||||
"DNSZONE": domain + ".",
|
||||
})
|
||||
code := r.Code()
|
||||
code := r.GetCode()
|
||||
if code == 545 {
|
||||
r = n.client.Request(map[string]string{
|
||||
"COMMAND": "CreateDNSZone",
|
||||
|
@@ -3,10 +3,10 @@ package hexonet
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
lr "github.com/hexonet/go-sdk/response/listresponse"
|
||||
"github.com/hexonet/go-sdk/response"
|
||||
)
|
||||
|
||||
// GetHXApiError returns an error including API error code and error description.
|
||||
func (n *HXClient) GetHXApiError(format string, objectid string, r *lr.ListResponse) error {
|
||||
return fmt.Errorf(format+" %s. [%s %s]", objectid, r.Code(), r.Description())
|
||||
func (n *HXClient) GetHXApiError(format string, objectid string, r *response.Response) error {
|
||||
return fmt.Errorf(format+" %s. [%s %s]", objectid, r.GetCode(), r.GetDescription())
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v2/providers"
|
||||
hxcl "github.com/hexonet/go-sdk/client"
|
||||
hxcl "github.com/hexonet/go-sdk/apiclient"
|
||||
)
|
||||
|
||||
// HXClient describes a connection to the hexonet API.
|
||||
@@ -14,7 +14,7 @@ type HXClient struct {
|
||||
APILogin string
|
||||
APIPassword string
|
||||
APIEntity string
|
||||
client *hxcl.Client
|
||||
client *hxcl.APIClient
|
||||
}
|
||||
|
||||
var features = providers.DocumentationNotes{
|
||||
@@ -34,14 +34,14 @@ var features = providers.DocumentationNotes{
|
||||
|
||||
func newProvider(conf map[string]string) (*HXClient, error) {
|
||||
api := &HXClient{
|
||||
client: hxcl.NewClient(),
|
||||
client: hxcl.NewAPIClient(),
|
||||
}
|
||||
api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"]
|
||||
if conf["debugmode"] == "1" {
|
||||
api.client.EnableDebugMode()
|
||||
}
|
||||
if len(conf["ipaddress"]) > 0 {
|
||||
api.client.SetIPAddress(conf["ipaddress"])
|
||||
api.client.SetRemoteIPAddress(conf["ipaddress"])
|
||||
}
|
||||
if api.APIEntity != "OTE" && api.APIEntity != "LIVE" {
|
||||
return nil, fmt.Errorf("wrong api system entity used. use \"OTE\" for OT&E system or \"LIVE\" for Live system")
|
||||
@@ -52,7 +52,7 @@ func newProvider(conf map[string]string) (*HXClient, error) {
|
||||
if api.APILogin == "" || api.APIPassword == "" {
|
||||
return nil, fmt.Errorf("missing login credentials apilogin or apipassword")
|
||||
}
|
||||
api.client.SetCredentials(api.APILogin, api.APIPassword, "")
|
||||
api.client.SetCredentials(api.APILogin, api.APIPassword)
|
||||
return api, nil
|
||||
}
|
||||
|
||||
|
@@ -45,11 +45,15 @@ func (n *HXClient) getNameserversRaw(domain string) ([]string, error) {
|
||||
"COMMAND": "StatusDomain",
|
||||
"DOMAIN": domain,
|
||||
})
|
||||
code := r.Code()
|
||||
code := r.GetCode()
|
||||
if code != 200 {
|
||||
return nil, n.GetHXApiError("Could not get status for domain", domain, r)
|
||||
}
|
||||
ns := r.GetColumn("NAMESERVER")
|
||||
nsColumn := r.GetColumn("NAMESERVER")
|
||||
if nsColumn == nil {
|
||||
return nil, fmt.Errorf("Error getting NAMESERVER column for domain: %s", domain)
|
||||
}
|
||||
ns := nsColumn.GetData()
|
||||
sort.Strings(ns)
|
||||
return ns, nil
|
||||
}
|
||||
@@ -91,9 +95,9 @@ func (n *HXClient) updateNameservers(ns []string, domain string) func() error {
|
||||
cmd[fmt.Sprintf("NAMESERVER%d", idx)] = ns
|
||||
}
|
||||
response := n.client.Request(cmd)
|
||||
code := response.Code()
|
||||
code := response.GetCode()
|
||||
if code != 200 {
|
||||
return fmt.Errorf(fmt.Sprintf("%d %s", code, response.Description()))
|
||||
return fmt.Errorf("%d %s", code, response.GetDescription())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -80,7 +80,11 @@ func (n *HXClient) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Corr
|
||||
changes = true
|
||||
fmt.Fprintln(buf, cre)
|
||||
rec := cre.Desired
|
||||
params[fmt.Sprintf("ADDRR%d", addrridx)] = n.createRecordString(rec, dc.Name)
|
||||
recordString, err := n.createRecordString(rec, dc.Name)
|
||||
if err != nil {
|
||||
return corrections, err
|
||||
}
|
||||
params[fmt.Sprintf("ADDRR%d", addrridx)] = recordString
|
||||
addrridx++
|
||||
}
|
||||
for _, d := range del {
|
||||
@@ -96,7 +100,11 @@ func (n *HXClient) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Corr
|
||||
old := chng.Existing.Original.(*HXRecord)
|
||||
new := chng.Desired
|
||||
params[fmt.Sprintf("DELRR%d", delrridx)] = n.deleteRecordString(old, dc.Name)
|
||||
params[fmt.Sprintf("ADDRR%d", addrridx)] = n.createRecordString(new, dc.Name)
|
||||
newRecordString, err := n.createRecordString(new, dc.Name)
|
||||
if err != nil {
|
||||
return corrections, err
|
||||
}
|
||||
params[fmt.Sprintf("ADDRR%d", addrridx)] = newRecordString
|
||||
addrridx++
|
||||
delrridx++
|
||||
}
|
||||
@@ -178,12 +186,16 @@ func (n *HXClient) getRecords(domain string) ([]*HXRecord, error) {
|
||||
}
|
||||
r := n.client.Request(cmd)
|
||||
if !r.IsSuccess() {
|
||||
if r.Code() == 545 {
|
||||
if r.GetCode() == 545 {
|
||||
return nil, n.GetHXApiError("Use `dnscontrol create-domains` to create not-existing zone", domain, r)
|
||||
}
|
||||
return nil, n.GetHXApiError("Failed loading resource records for zone", domain, r)
|
||||
}
|
||||
rrs := r.GetColumn("RR")
|
||||
rrColumn := r.GetColumn("RR")
|
||||
if rrColumn == nil {
|
||||
return nil, fmt.Errorf("Error getting RR column for domain: %s", domain)
|
||||
}
|
||||
rrs := rrColumn.GetData()
|
||||
for _, rr := range rrs {
|
||||
spl := strings.Split(rr, " ")
|
||||
if spl[3] != "SOA" {
|
||||
@@ -212,7 +224,7 @@ func (n *HXClient) getRecords(domain string) ([]*HXRecord, error) {
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func (n *HXClient) createRecordString(rc *models.RecordConfig, domain string) string {
|
||||
func (n *HXClient) createRecordString(rc *models.RecordConfig, domain string) (string, error) {
|
||||
record := &HXRecord{
|
||||
DomainName: domain,
|
||||
Host: rc.GetLabel(),
|
||||
@@ -231,10 +243,13 @@ func (n *HXClient) createRecordString(rc *models.RecordConfig, domain string) st
|
||||
case "TXT":
|
||||
record.Answer = encodeTxt(rc.TxtStrings)
|
||||
case "SRV":
|
||||
if rc.GetTargetField() == "." {
|
||||
return "", fmt.Errorf("SRV records with empty targets are not supported (as of 2020-02-27, the API returns 'Invalid attribute value syntax')")
|
||||
}
|
||||
record.Answer = fmt.Sprintf("%d %d %v", rc.SrvWeight, rc.SrvPort, record.Answer)
|
||||
record.Priority = uint32(rc.SrvPriority)
|
||||
default:
|
||||
panic(fmt.Sprintf("createRecord rtype %v unimplemented", rc.Type))
|
||||
panic(fmt.Sprintf("createRecordString rtype %v unimplemented", rc.Type))
|
||||
// We panic so that we quickly find any switch statements
|
||||
// that have not been updated for a new RR type.
|
||||
}
|
||||
@@ -244,7 +259,7 @@ func (n *HXClient) createRecordString(rc *models.RecordConfig, domain string) st
|
||||
str += fmt.Sprint(record.Priority) + " "
|
||||
}
|
||||
str += record.Answer
|
||||
return str
|
||||
return str, nil
|
||||
}
|
||||
|
||||
func (n *HXClient) deleteRecordString(record *HXRecord, domain string) string {
|
||||
|
Reference in New Issue
Block a user