NAMEDOTCOM needs parameterization to permit integration testing.

This commit is contained in:
Tom Limoncelli 2017-07-13 11:52:56 -04:00
parent 4fc8bd86fd
commit d346d561a0
6 changed files with 31 additions and 21 deletions

View file

@ -19,6 +19,11 @@ In your providers config json file you must provide your name.com api username a
}
{% endhighlight %}
There is another key name `apiurl` but it is optional and defaults to the correct value. If you
want to use the test environment ("OT&E"), then add this:
"apiurl": "https://api.dev.name.com",
## Metadata
This provider does not recognize any special metadata fields unique to name.com.
@ -53,4 +58,4 @@ D("example.tld", REG_NAMECOM, DnsProvider(R53),
In order to activate api functionality on your name.com account, you must apply to the api program.
The application form is [located here](https://www.name.com/reseller/apply). It usually takes a few days to get a response.
After you are accepted, you should receive your api token via email.
After you are accepted, you should receive your api token via email.

View file

@ -34,7 +34,8 @@
"NAMEDOTCOM": {
"apikey": "$NAMEDOTCOM_KEY",
"apiurl": "$NAMEDOTCOM_URL",
"apiuser": "$NAMEDOTCOM_USER"
"apiuser": "$NAMEDOTCOM_USER",
"domain": "$NAMEDOTCOM_DOMAIN"
},
"ROUTE53": {
"KeyId": "$R53_KEY_ID",

View file

@ -11,7 +11,10 @@ import (
"github.com/StackExchange/dnscontrol/providers"
)
const defaultApiBase = "https://api.name.com/api"
type nameDotCom struct {
APIUrl string `json:"apiurl"`
APIUser string `json:"apiuser"`
APIKey string `json:"apikey"`
}
@ -26,10 +29,13 @@ func newDsp(conf map[string]string, meta json.RawMessage) (providers.DNSServiceP
func newProvider(conf map[string]string) (*nameDotCom, error) {
api := &nameDotCom{}
api.APIUser, api.APIKey = conf["apiuser"], conf["apikey"]
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.")
}
if api.APIUrl == "" {
api.APIUrl = defaultApiBase
}
return api, nil
}
@ -67,8 +73,6 @@ func (r *apiResult) getErr() error {
return nil
}
var apiBase = "https://api.name.com/api"
//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)

View file

@ -31,7 +31,7 @@ func (n *nameDotCom) GetNameservers(domain string) ([]*models.Nameserver, error)
func (n *nameDotCom) getNameserversRaw(domain string) ([]string, error) {
result := &getDomainResult{}
if err := n.get(apiGetDomain(domain), result); err != nil {
if err := n.get(n.apiGetDomain(domain), result); err != nil {
return nil, err
}
if err := result.getErr(); err != nil {
@ -69,11 +69,11 @@ func (n *nameDotCom) GetRegistrarCorrections(dc *models.DomainConfig) ([]*models
//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 apiGetDomain(domain string) string {
return fmt.Sprintf("%s/domain/get/%s", apiBase, domain)
func (n *nameDotCom) apiGetDomain(domain string) string {
return fmt.Sprintf("%s/domain/get/%s", n.APIUrl, domain)
}
func apiUpdateNS(domain string) string {
return fmt.Sprintf("%s/domain/update_nameservers/%s", apiBase, domain)
func (n *nameDotCom) apiUpdateNS(domain string) string {
return fmt.Sprintf("%s/domain/update_nameservers/%s", n.APIUrl, domain)
}
type getDomainResult struct {
@ -87,7 +87,7 @@ func (n *nameDotCom) updateNameservers(ns []string, domain string) func() error
dat := struct {
Nameservers []string `json:"nameservers"`
}{ns}
resp, err := n.post(apiUpdateNS(domain), dat)
resp, err := n.post(n.apiUpdateNS(domain), dat)
if err != nil {
return err
}

View file

@ -23,8 +23,8 @@ func setup() {
client = &nameDotCom{
APIUser: "bob",
APIKey: "123",
APIUrl: server.URL,
}
apiBase = server.URL
}
func teardown() {

View file

@ -58,14 +58,14 @@ func (n *nameDotCom) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Co
return corrections, nil
}
func apiGetRecords(domain string) string {
return fmt.Sprintf("%s/dns/list/%s", apiBase, domain)
func (n *nameDotCom) apiGetRecords(domain string) string {
return fmt.Sprintf("%s/dns/list/%s", n.APIUrl, domain)
}
func apiCreateRecord(domain string) string {
return fmt.Sprintf("%s/dns/create/%s", apiBase, domain)
func (n *nameDotCom) apiCreateRecord(domain string) string {
return fmt.Sprintf("%s/dns/create/%s", n.APIUrl, domain)
}
func apiDeleteRecord(domain string) string {
return fmt.Sprintf("%s/dns/delete/%s", apiBase, domain)
func (n *nameDotCom) apiDeleteRecord(domain string) string {
return fmt.Sprintf("%s/dns/delete/%s", n.APIUrl, domain)
}
type nameComRecord struct {
@ -108,7 +108,7 @@ type listRecordsResponse struct {
func (n *nameDotCom) getRecords(domain string) ([]*nameComRecord, error) {
result := &listRecordsResponse{}
err := n.get(apiGetRecords(domain), result)
err := n.get(n.apiGetRecords(domain), result)
if err != nil {
return nil, err
}
@ -149,7 +149,7 @@ func (n *nameDotCom) createRecord(rc *models.RecordConfig, domain string) error
if dat.Hostname == "@" {
dat.Hostname = ""
}
resp, err := n.post(apiCreateRecord(domain), dat)
resp, err := n.post(n.apiCreateRecord(domain), dat)
if err != nil {
return err
}
@ -160,7 +160,7 @@ func (n *nameDotCom) deleteRecord(id, domain string) error {
dat := struct {
ID string `json:"record_id"`
}{id}
resp, err := n.post(apiDeleteRecord(domain), dat)
resp, err := n.post(n.apiDeleteRecord(domain), dat)
if err != nil {
return err
}