2018-01-09 12:53:16 -05: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-22 18:31:50 -06:00
package namedotcom
import (
"encoding/json"
"github.com/StackExchange/dnscontrol/providers"
2018-01-10 14:49:20 -07:00
"github.com/namedotcom/go/namecom"
2018-02-05 16:17:20 -05:00
"github.com/pkg/errors"
2016-08-22 18:31:50 -06:00
)
2018-01-10 14:49:20 -07:00
const defaultAPIBase = "api.name.com"
2017-07-13 11:52:56 -04:00
2018-02-15 12:02:50 -05:00
// NameCom describes a connection to the NDC API.
2018-01-10 14:49:20 -07:00
type NameCom struct {
2017-07-13 11:52:56 -04:00
APIUrl string ` json:"apiurl" `
2016-08-22 18:31:50 -06:00
APIUser string ` json:"apiuser" `
APIKey string ` json:"apikey" `
2018-01-10 14:49:20 -07:00
client * namecom . NameCom
2016-08-22 18:31:50 -06:00
}
2018-01-04 19:19:35 -05: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 ( ) ,
2019-05-27 15:10:00 -04:00
providers . CanUseTXTMulti : providers . Cannot ( ) ,
2017-09-14 16:13:17 -04:00
providers . DocCreateDomains : providers . Cannot ( "New domains require registration" ) ,
2018-01-04 19:19:35 -05:00
providers . DocDualHost : providers . Cannot ( "Apex NS records not editable" ) ,
2017-09-14 16:13:17 -04:00
providers . DocOfficiallySupported : providers . Can ( ) ,
}
2016-08-22 18:31:50 -06: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-10 14:49:20 -07: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 11:52:56 -04:00
api . APIUser , api . APIKey , api . APIUrl = conf [ "apiuser" ] , conf [ "apikey" ] , conf [ "apiurl" ]
2016-08-22 18:31:50 -06:00
if api . APIKey == "" || api . APIUser == "" {
2018-02-05 16:17:20 -05:00
return nil , errors . Errorf ( "missing Name.com apikey or apiuser" )
2016-08-22 18:31:50 -06:00
}
2017-07-13 11:52:56 -04:00
if api . APIUrl == "" {
2018-01-09 12:53:16 -05:00
api . APIUrl = defaultAPIBase
2017-07-13 11:52:56 -04:00
}
2016-08-22 18:31:50 -06:00
return api , nil
}
func init ( ) {
providers . RegisterRegistrarType ( "NAMEDOTCOM" , newReg )
2018-01-04 19:19:35 -05:00
providers . RegisterDomainServiceProviderType ( "NAMEDOTCOM" , newDsp , features )
2016-08-22 18:31:50 -06:00
}