mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
@@ -1,4 +1,4 @@
|
||||
//Package namedotcom implements a registrar that uses the name.com api to set name servers. It will self register it's providers when imported.
|
||||
// Package namedotcom implements a registrar that uses the name.com api to set name servers. It will self register it's providers when imported.
|
||||
package namedotcom
|
||||
|
||||
import (
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/StackExchange/dnscontrol/providers"
|
||||
)
|
||||
|
||||
const defaultApiBase = "https://api.name.com/api"
|
||||
const defaultAPIBase = "https://api.name.com/api"
|
||||
|
||||
type nameDotCom struct {
|
||||
APIUrl string `json:"apiurl"`
|
||||
@@ -40,10 +40,10 @@ func newProvider(conf map[string]string) (*nameDotCom, error) {
|
||||
api := &nameDotCom{}
|
||||
api.APIUser, api.APIKey, api.APIUrl = conf["apiuser"], conf["apikey"], conf["apiurl"]
|
||||
if api.APIKey == "" || api.APIUser == "" {
|
||||
return nil, fmt.Errorf("Name.com apikey and apiuser must be provided.")
|
||||
return nil, fmt.Errorf("missing Name.com apikey or apiuser")
|
||||
}
|
||||
if api.APIUrl == "" {
|
||||
api.APIUrl = defaultApiBase
|
||||
api.APIUrl = defaultAPIBase
|
||||
}
|
||||
return api, nil
|
||||
}
|
||||
@@ -53,9 +53,7 @@ func init() {
|
||||
providers.RegisterDomainServiceProviderType("NAMEDOTCOM", newDsp, features)
|
||||
}
|
||||
|
||||
///
|
||||
//various http helpers for interacting with api
|
||||
///
|
||||
// various http helpers for interacting with api
|
||||
|
||||
func (n *nameDotCom) addAuth(r *http.Request) {
|
||||
r.Header.Add("Api-Username", n.APIUser)
|
||||
@@ -82,7 +80,7 @@ func (r *apiResult) getErr() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//perform http GET and unmarshal response json into target struct
|
||||
// perform http GET and unmarshal response json into target struct
|
||||
func (n *nameDotCom) get(url string, target interface{}) error {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
|
@@ -12,9 +12,9 @@ import (
|
||||
var nsRegex = regexp.MustCompile(`ns([1-4])[a-z]{3}\.name\.com`)
|
||||
|
||||
func (n *nameDotCom) GetNameservers(domain string) ([]*models.Nameserver, error) {
|
||||
//This is an interesting edge case. Name.com expects you to SET the nameservers to ns[1-4].name.com,
|
||||
//but it will internally set it to ns1xyz.name.com, where xyz is a uniqueish 3 letters.
|
||||
//In order to avoid endless loops, we will use the unique nameservers if present, or else the generic ones if not.
|
||||
// This is an interesting edge case. Name.com expects you to SET the nameservers to ns[1-4].name.com,
|
||||
// but it will internally set it to ns1xyz.name.com, where xyz is a uniqueish 3 letters.
|
||||
// In order to avoid endless loops, we will use the unique nameservers if present, or else the generic ones if not.
|
||||
nss, err := n.getNameserversRaw(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -22,7 +22,7 @@ func (n *nameDotCom) GetNameservers(domain string) ([]*models.Nameserver, error)
|
||||
toUse := []string{"ns1.name.com", "ns2.name.com", "ns3.name.com", "ns4.name.com"}
|
||||
for _, ns := range nss {
|
||||
if matches := nsRegex.FindStringSubmatch(ns); len(matches) == 2 && len(matches[1]) == 1 {
|
||||
idx := matches[1][0] - '1' //regex ensures proper range
|
||||
idx := matches[1][0] - '1' // regex ensures proper range
|
||||
toUse[idx] = matches[0]
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func (n *nameDotCom) GetRegistrarCorrections(dc *models.DomainConfig) ([]*models
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
//even if you provide them "ns1.name.com", they will set it to "ns1qrt.name.com". This will match that pattern to see if defaults are in use.
|
||||
// even if you provide them "ns1.name.com", they will set it to "ns1qrt.name.com". This will match that pattern to see if defaults are in use.
|
||||
var defaultNsRegexp = regexp.MustCompile(`ns1[a-z]{0,3}\.name\.com,ns2[a-z]{0,3}\.name\.com,ns3[a-z]{0,3}\.name\.com,ns4[a-z]{0,3}\.name\.com`)
|
||||
|
||||
func (n *nameDotCom) apiGetDomain(domain string) string {
|
||||
@@ -91,9 +91,6 @@ func (n *nameDotCom) updateNameservers(ns []string, domain string) func() error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = resp.getErr(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return resp.getErr()
|
||||
}
|
||||
}
|
||||
|
@@ -83,7 +83,7 @@ func TestGetCorrections(t *testing.T) {
|
||||
{`"bar.ns.tld","foo.ns.tld"`, 0},
|
||||
{`"foo.ns.tld"`, 1},
|
||||
{`"1.ns.aaa","2.ns.www"`, 1},
|
||||
{"ERR", -1}, //-1 means we expect an error
|
||||
{"ERR", -1}, // -1 means we expect an error
|
||||
{"MSGERR", -1},
|
||||
} {
|
||||
setup()
|
||||
@@ -155,12 +155,12 @@ func TestGetNameservers(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
givenNs, expected string
|
||||
}{
|
||||
//empty or external dsp, use ns1-4.name.com
|
||||
// empty or external dsp, use ns1-4.name.com
|
||||
{"", d},
|
||||
{`"foo.ns.tld","bar.ns.tld"`, d},
|
||||
//if already on name.com, use the existing nameservers
|
||||
// if already on name.com, use the existing nameservers
|
||||
{`"ns1aaa.name.com","ns2bbb.name.com","ns3ccc.name.com","ns4ddd.name.com"`, "ns1aaa.name.com,ns2bbb.name.com,ns3ccc.name.com,ns4ddd.name.com"},
|
||||
//also handle half and half
|
||||
// also handle half and half
|
||||
{`"ns1aaa.name.com","ns2bbb.name.com","ns3ccc.aws.net","ns4ddd.awsdns.org"`, "ns1aaa.name.com,ns2bbb.name.com,ns3.name.com,ns4.name.com"},
|
||||
{`"nsa.azuredns.com","ns2b.gandhi.net","ns3ccc.name.com","ns4ddd.name.com"`, "ns1.name.com,ns2.name.com,ns3ccc.name.com,ns4ddd.name.com"},
|
||||
} {
|
||||
|
@@ -160,7 +160,7 @@ func (n *nameDotCom) createRecord(rc *models.RecordConfig, domain string) error
|
||||
if target[len(target)-1] == '.' {
|
||||
target = target[:len(target)-1]
|
||||
} else {
|
||||
return fmt.Errorf("Unexpected. CNAME/MX/NS target did not end with dot.\n")
|
||||
return fmt.Errorf("unexpected: CNAME/MX/NS target did not end with dot")
|
||||
}
|
||||
}
|
||||
dat := struct {
|
||||
|
Reference in New Issue
Block a user