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"
Switch to Go 1.13 error wrapping (#604)
* Replaced errors.Wrap with fmt.Errorf (#589)
* Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Replaced errors.Wrapf with fmt.Errorf (#589)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\)
* Replace: fmt.Errorf($2: %w$3$4, $1)
* Replaced errors.Errorf with fmt.Errorf (#589)
* Find: errors\.Errorf
Replace: fmt.Errorf
* Cleaned up remaining imports
* Cleanup
* Regenerate provider support matrix
This was broken by #533 ... and it's now the third time this has been missed.
2020-01-29 00:06:56 +08:00
"fmt"
2016-08-23 08:31:50 +08:00
2018-01-11 05:49:20 +08:00
"github.com/namedotcom/go/namecom"
Switch to Go 1.13 error wrapping (#604)
* Replaced errors.Wrap with fmt.Errorf (#589)
* Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Replaced errors.Wrapf with fmt.Errorf (#589)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\)
* Replace: fmt.Errorf($2: %w$3$4, $1)
* Replaced errors.Errorf with fmt.Errorf (#589)
* Find: errors\.Errorf
Replace: fmt.Errorf
* Cleaned up remaining imports
* Cleanup
* Regenerate provider support matrix
This was broken by #533 ... and it's now the third time this has been missed.
2020-01-29 00:06:56 +08:00
2020-04-15 04:47:30 +08:00
"github.com/StackExchange/dnscontrol/v3/providers"
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
2020-10-26 21:25:30 +08:00
// namedotcomProvider describes a connection to the NDC API.
type namedotcomProvider 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" ) ,
2019-11-15 00:25:20 +08:00
providers . CanUseSRV : providers . Can ( "SRV records with empty targets are not supported" ) ,
2019-05-28 03:10:00 +08:00
providers . CanUseTXTMulti : providers . Cannot ( ) ,
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 ( ) ,
2020-02-22 04:03:27 +08:00
providers . CanGetZones : providers . Can ( ) ,
2017-09-15 04:13:17 +08:00
}
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 )
}
2020-10-26 21:25:30 +08:00
func newProvider ( conf map [ string ] string ) ( * namedotcomProvider , error ) {
api := & namedotcomProvider {
2018-01-11 05:49:20 +08:00
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 == "" {
Switch to Go 1.13 error wrapping (#604)
* Replaced errors.Wrap with fmt.Errorf (#589)
* Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Replaced errors.Wrapf with fmt.Errorf (#589)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\)
Replace: fmt.Errorf($2: %w$3, $1)
* Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\)
* Replace: fmt.Errorf($2: %w$3$4, $1)
* Replaced errors.Errorf with fmt.Errorf (#589)
* Find: errors\.Errorf
Replace: fmt.Errorf
* Cleaned up remaining imports
* Cleanup
* Regenerate provider support matrix
This was broken by #533 ... and it's now the third time this has been missed.
2020-01-29 00:06:56 +08:00
return nil , fmt . 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
}