mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-11 09:59:59 +08:00
444b893e1b
* maint: sort lists in build/generate/featureMatrix.go * maint: sort lists in docs/byo-secrets.md * maint: sort lists in models/record.go * maint: sort lists in pkg/normalize/validate.go * maint: sort lists in providers/activedir/activedirProvider.go * maint: sort lists in providers/akamaiedgedns/akamaiEdgeDnsProvider.go * maint: sort lists in providers/axfrddns/axfrddnsProvider.go * maint: sort lists in providers/azuredns/azureDnsProvider.go * maint: sort lists in providers/cloudflare/cloudflareProvider.go * maint: sort lists in providers/cloudns/cloudnsProvider.go * maint: sort lists in providers/desec/desecProvider.go * maint: sort lists in providers/digitalocean/digitaloceanProvider.go * maint: sort lists in providers/dnsimple/dnsimpleProvider.go * maint: sort lists in providers/dnsmadeeasy/dnsMadeEasyProvider.go * maint: sort lists in providers/exoscale/exoscaleProvider.go * maint: sort lists in providers/gandiv5/gandi_v5Provider.go * maint: sort lists in providers/hedns/hednsProvider.go * maint: sort lists in providers/hetzner/hetznerProvider.go * maint: sort lists in providers/hexonet/hexonetProvider.go * maint: sort lists in providers/inwx/inwxProvider.go * maint: sort lists in providers/linode/linodeProvider.go * maint: sort lists in providers/namecheap/namecheapProvider.go * maint: sort lists in providers/namedotcom/namedotcomProvider.go * maint: sort lists in providers/netcup/netcupProvider.go * maint: sort lists in providers/ns1/ns1Provider.go * maint: sort lists in providers/octodns/octodnsProvider.go * maint: sort lists in providers/oracle/oracleProvider.go * maint: sort lists in providers/ovh/ovhProvider.go * maint: sort lists in providers/packetframe/packetframeProvider.go * maint: sort lists in providers/powerdns/powerdnsProvider.go * maint: sort lists in providers/route53/route53Provider.go * maint: sort lists in providers/vultr/vultrProvider.go * Update go:build pragmas for windows * More sorting * go generate
71 lines
2.3 KiB
Go
71 lines
2.3 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"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/namedotcom/go/namecom"
|
|
|
|
"github.com/StackExchange/dnscontrol/v3/providers"
|
|
)
|
|
|
|
const defaultAPIBase = "api.name.com"
|
|
|
|
// namedotcomProvider describes a connection to the NDC API.
|
|
type namedotcomProvider struct {
|
|
APIUrl string `json:"apiurl"`
|
|
APIUser string `json:"apiuser"`
|
|
APIKey string `json:"apikey"`
|
|
client *namecom.NameCom
|
|
}
|
|
|
|
var features = providers.DocumentationNotes{
|
|
providers.CanGetZones: providers.Can(),
|
|
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.DocCreateDomains: providers.Cannot("New domains require registration"),
|
|
providers.DocDualHost: providers.Can(),
|
|
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) (*namedotcomProvider, error) {
|
|
api := &namedotcomProvider{
|
|
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, fmt.Errorf("missing Name.com apikey or apiuser")
|
|
}
|
|
if api.APIUrl == "" {
|
|
api.APIUrl = defaultAPIBase
|
|
}
|
|
|
|
// Set the timeout to a high value. Currently we get timeouts and
|
|
// the namecom library doesn't make it easy to do a clean
|
|
// retry-on-timeout or retry-on-429. As a work-around we just give
|
|
// it more time to finish.
|
|
api.client.Client.Timeout = 60 * time.Second
|
|
|
|
return api, nil
|
|
}
|
|
|
|
func init() {
|
|
providers.RegisterRegistrarType("NAMEDOTCOM", newReg)
|
|
fns := providers.DspFuncs{
|
|
Initializer: newDsp,
|
|
RecordAuditor: AuditRecords,
|
|
}
|
|
providers.RegisterDomainServiceProviderType("NAMEDOTCOM", fns, features)
|
|
}
|