1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

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

@ -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)