2018-01-10 01:53:16 +08:00
// Package namedotcom implements a registrar that uses the name.com api to set name servers. It will self register it's providers when imported.
2016-08-23 08:31:50 +08:00
package namedotcom
import (
"encoding/json"
"github.com/StackExchange/dnscontrol/providers"
2018-01-11 05:49:20 +08:00
"github.com/namedotcom/go/namecom"
2018-02-06 05:17:20 +08:00
"github.com/pkg/errors"
2016-08-23 08:31:50 +08:00
)
2018-01-11 05:49:20 +08:00
const defaultAPIBase = "api.name.com"
2017-07-13 23:52:56 +08:00
2018-02-16 01:02:50 +08:00
// NameCom describes a connection to the NDC API.
2018-01-11 05:49:20 +08:00
type NameCom struct {
2017-07-13 23:52:56 +08:00
APIUrl string ` json:"apiurl" `
2016-08-23 08:31:50 +08:00
APIUser string ` json:"apiuser" `
APIKey string ` json:"apikey" `
2018-01-11 05:49:20 +08:00
client * namecom . NameCom
2016-08-23 08:31:50 +08:00
}
2018-01-05 08:19:35 +08:00
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 ( ) ,
2018-01-11 20:23:59 +08:00
providers . CanUseTXTMulti : providers . Can ( ) ,
2017-09-15 04:13:17 +08:00
providers . DocCreateDomains : providers . Cannot ( "New domains require registration" ) ,
2018-01-05 08:19:35 +08:00
providers . DocDualHost : providers . Cannot ( "Apex NS records not editable" ) ,
2017-09-15 04:13:17 +08:00
providers . DocOfficiallySupported : providers . Can ( ) ,
}
2016-08-23 08:31:50 +08:00
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 )
}
2018-01-11 05:49:20 +08:00
func newProvider ( conf map [ string ] string ) ( * NameCom , error ) {
api := & NameCom {
client : namecom . New ( conf [ "apiuser" ] , conf [ "apikey" ] ) ,
}
api . client . Server = conf [ "apiurl" ]
2017-07-13 23:52:56 +08:00
api . APIUser , api . APIKey , api . APIUrl = conf [ "apiuser" ] , conf [ "apikey" ] , conf [ "apiurl" ]
2016-08-23 08:31:50 +08:00
if api . APIKey == "" || api . APIUser == "" {
2018-02-06 05:17:20 +08:00
return nil , errors . Errorf ( "missing Name.com apikey or apiuser" )
2016-08-23 08:31:50 +08:00
}
2017-07-13 23:52:56 +08:00
if api . APIUrl == "" {
2018-01-10 01:53:16 +08:00
api . APIUrl = defaultAPIBase
2017-07-13 23:52:56 +08:00
}
2016-08-23 08:31:50 +08:00
return api , nil
}
func init ( ) {
providers . RegisterRegistrarType ( "NAMEDOTCOM" , newReg )
2018-01-05 08:19:35 +08:00
providers . RegisterDomainServiceProviderType ( "NAMEDOTCOM" , newDsp , features )
2016-08-23 08:31:50 +08:00
}