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:
@@ -19,6 +19,11 @@ In your providers config json file you must provide your name.com api username a
|
|||||||
}
|
}
|
||||||
{% endhighlight %}
|
{% 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
|
## Metadata
|
||||||
|
|
||||||
This provider does not recognize any special metadata fields unique to name.com.
|
This provider does not recognize any special metadata fields unique to name.com.
|
||||||
|
@@ -34,7 +34,8 @@
|
|||||||
"NAMEDOTCOM": {
|
"NAMEDOTCOM": {
|
||||||
"apikey": "$NAMEDOTCOM_KEY",
|
"apikey": "$NAMEDOTCOM_KEY",
|
||||||
"apiurl": "$NAMEDOTCOM_URL",
|
"apiurl": "$NAMEDOTCOM_URL",
|
||||||
"apiuser": "$NAMEDOTCOM_USER"
|
"apiuser": "$NAMEDOTCOM_USER",
|
||||||
|
"domain": "$NAMEDOTCOM_DOMAIN"
|
||||||
},
|
},
|
||||||
"ROUTE53": {
|
"ROUTE53": {
|
||||||
"KeyId": "$R53_KEY_ID",
|
"KeyId": "$R53_KEY_ID",
|
||||||
|
@@ -11,7 +11,10 @@ import (
|
|||||||
"github.com/StackExchange/dnscontrol/providers"
|
"github.com/StackExchange/dnscontrol/providers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const defaultApiBase = "https://api.name.com/api"
|
||||||
|
|
||||||
type nameDotCom struct {
|
type nameDotCom struct {
|
||||||
|
APIUrl string `json:"apiurl"`
|
||||||
APIUser string `json:"apiuser"`
|
APIUser string `json:"apiuser"`
|
||||||
APIKey string `json:"apikey"`
|
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) {
|
func newProvider(conf map[string]string) (*nameDotCom, error) {
|
||||||
api := &nameDotCom{}
|
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 == "" {
|
if api.APIKey == "" || api.APIUser == "" {
|
||||||
return nil, fmt.Errorf("Name.com apikey and apiuser must be provided.")
|
return nil, fmt.Errorf("Name.com apikey and apiuser must be provided.")
|
||||||
}
|
}
|
||||||
|
if api.APIUrl == "" {
|
||||||
|
api.APIUrl = defaultApiBase
|
||||||
|
}
|
||||||
return api, nil
|
return api, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,8 +73,6 @@ func (r *apiResult) getErr() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var apiBase = "https://api.name.com/api"
|
|
||||||
|
|
||||||
//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 {
|
func (n *nameDotCom) get(url string, target interface{}) error {
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
@@ -31,7 +31,7 @@ func (n *nameDotCom) GetNameservers(domain string) ([]*models.Nameserver, error)
|
|||||||
|
|
||||||
func (n *nameDotCom) getNameserversRaw(domain string) ([]string, error) {
|
func (n *nameDotCom) getNameserversRaw(domain string) ([]string, error) {
|
||||||
result := &getDomainResult{}
|
result := &getDomainResult{}
|
||||||
if err := n.get(apiGetDomain(domain), result); err != nil {
|
if err := n.get(n.apiGetDomain(domain), result); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := result.getErr(); err != nil {
|
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.
|
//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`)
|
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 {
|
func (n *nameDotCom) apiGetDomain(domain string) string {
|
||||||
return fmt.Sprintf("%s/domain/get/%s", apiBase, domain)
|
return fmt.Sprintf("%s/domain/get/%s", n.APIUrl, domain)
|
||||||
}
|
}
|
||||||
func apiUpdateNS(domain string) string {
|
func (n *nameDotCom) apiUpdateNS(domain string) string {
|
||||||
return fmt.Sprintf("%s/domain/update_nameservers/%s", apiBase, domain)
|
return fmt.Sprintf("%s/domain/update_nameservers/%s", n.APIUrl, domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
type getDomainResult struct {
|
type getDomainResult struct {
|
||||||
@@ -87,7 +87,7 @@ func (n *nameDotCom) updateNameservers(ns []string, domain string) func() error
|
|||||||
dat := struct {
|
dat := struct {
|
||||||
Nameservers []string `json:"nameservers"`
|
Nameservers []string `json:"nameservers"`
|
||||||
}{ns}
|
}{ns}
|
||||||
resp, err := n.post(apiUpdateNS(domain), dat)
|
resp, err := n.post(n.apiUpdateNS(domain), dat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -23,8 +23,8 @@ func setup() {
|
|||||||
client = &nameDotCom{
|
client = &nameDotCom{
|
||||||
APIUser: "bob",
|
APIUser: "bob",
|
||||||
APIKey: "123",
|
APIKey: "123",
|
||||||
|
APIUrl: server.URL,
|
||||||
}
|
}
|
||||||
apiBase = server.URL
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func teardown() {
|
func teardown() {
|
||||||
|
@@ -58,14 +58,14 @@ func (n *nameDotCom) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Co
|
|||||||
return corrections, nil
|
return corrections, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiGetRecords(domain string) string {
|
func (n *nameDotCom) apiGetRecords(domain string) string {
|
||||||
return fmt.Sprintf("%s/dns/list/%s", apiBase, domain)
|
return fmt.Sprintf("%s/dns/list/%s", n.APIUrl, domain)
|
||||||
}
|
}
|
||||||
func apiCreateRecord(domain string) string {
|
func (n *nameDotCom) apiCreateRecord(domain string) string {
|
||||||
return fmt.Sprintf("%s/dns/create/%s", apiBase, domain)
|
return fmt.Sprintf("%s/dns/create/%s", n.APIUrl, domain)
|
||||||
}
|
}
|
||||||
func apiDeleteRecord(domain string) string {
|
func (n *nameDotCom) apiDeleteRecord(domain string) string {
|
||||||
return fmt.Sprintf("%s/dns/delete/%s", apiBase, domain)
|
return fmt.Sprintf("%s/dns/delete/%s", n.APIUrl, domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
type nameComRecord struct {
|
type nameComRecord struct {
|
||||||
@@ -108,7 +108,7 @@ type listRecordsResponse struct {
|
|||||||
|
|
||||||
func (n *nameDotCom) getRecords(domain string) ([]*nameComRecord, error) {
|
func (n *nameDotCom) getRecords(domain string) ([]*nameComRecord, error) {
|
||||||
result := &listRecordsResponse{}
|
result := &listRecordsResponse{}
|
||||||
err := n.get(apiGetRecords(domain), result)
|
err := n.get(n.apiGetRecords(domain), result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,7 @@ func (n *nameDotCom) createRecord(rc *models.RecordConfig, domain string) error
|
|||||||
if dat.Hostname == "@" {
|
if dat.Hostname == "@" {
|
||||||
dat.Hostname = ""
|
dat.Hostname = ""
|
||||||
}
|
}
|
||||||
resp, err := n.post(apiCreateRecord(domain), dat)
|
resp, err := n.post(n.apiCreateRecord(domain), dat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -160,7 +160,7 @@ func (n *nameDotCom) deleteRecord(id, domain string) error {
|
|||||||
dat := struct {
|
dat := struct {
|
||||||
ID string `json:"record_id"`
|
ID string `json:"record_id"`
|
||||||
}{id}
|
}{id}
|
||||||
resp, err := n.post(apiDeleteRecord(domain), dat)
|
resp, err := n.post(n.apiDeleteRecord(domain), dat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user