dnscontrol/providers/namedotcom/namedotcomProvider.go
Patrick Gaskin 2f83aa9302 Internals: Switch to v2 go.mod, drop GOPATH, and fix Azure Pipelines (#595)
* Switched to v2 go.mod

Also set GO111MODULE=on in build stuff to always use Go modules
even when in GOPATH.

* Ensure go.mod, go.sum, and vendor are up to date

* Attempt to fix Azure pipelines

* Add set -e to properly fail on exit (it didn't seem to be
  propagating properly before).
* Set workingDirectory for GoFmt and GoGen (this might be why it
  fails unlike compile and unitests).

* Another attempt to fix Azure Pipelines

* Use the Go env template for all go-related jobs.

* Completely fixed Azure Pipelines

* Added a display name to GoFmt for consistency.
* Fixed diffs for GoFmt and GoGen.
* Show git status for checks.

* Drop GOPATH for tests

TODO: Do the same for integration tests.

* Drop GOPATH for integration tests

* Show more diffs

* Regenerate provider support matrix

This wasn't done in #590...
2020-01-28 10:42:31 -05:00

58 lines
2 KiB
Go

// 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 (
"encoding/json"
"github.com/StackExchange/dnscontrol/v2/providers"
"github.com/namedotcom/go/namecom"
"github.com/pkg/errors"
)
const defaultAPIBase = "api.name.com"
// NameCom describes a connection to the NDC API.
type NameCom struct {
APIUrl string `json:"apiurl"`
APIUser string `json:"apiuser"`
APIKey string `json:"apikey"`
client *namecom.NameCom
}
var features = providers.DocumentationNotes{
providers.CanUseAlias: providers.Can(),
providers.CanUsePTR: providers.Cannot("PTR records are not supported (See Link)", "https://www.name.com/support/articles/205188508-Reverse-DNS-records"),
providers.CanUseSRV: providers.Can("SRV records with empty targets are not supported"),
providers.CanUseTXTMulti: providers.Cannot(),
providers.DocCreateDomains: providers.Cannot("New domains require registration"),
providers.DocDualHost: providers.Cannot("Apex NS records not editable"),
providers.DocOfficiallySupported: providers.Can(),
}
func newReg(conf map[string]string) (providers.Registrar, error) {
return newProvider(conf)
}
func newDsp(conf map[string]string, meta json.RawMessage) (providers.DNSServiceProvider, error) {
return newProvider(conf)
}
func newProvider(conf map[string]string) (*NameCom, error) {
api := &NameCom{
client: namecom.New(conf["apiuser"], conf["apikey"]),
}
api.client.Server = conf["apiurl"]
api.APIUser, api.APIKey, api.APIUrl = conf["apiuser"], conf["apikey"], conf["apiurl"]
if api.APIKey == "" || api.APIUser == "" {
return nil, errors.Errorf("missing Name.com apikey or apiuser")
}
if api.APIUrl == "" {
api.APIUrl = defaultAPIBase
}
return api, nil
}
func init() {
providers.RegisterRegistrarType("NAMEDOTCOM", newReg)
providers.RegisterDomainServiceProviderType("NAMEDOTCOM", newDsp, features)
}