github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/providers/namedotcom/namedotcomProvider.go (about)

     1  // Package namedotcom implements a registrar that uses the name.com api to set name servers. It will self register it's providers when imported.
     2  package namedotcom
     3  
     4  import (
     5  	"encoding/json"
     6  	"fmt"
     7  
     8  	"github.com/namedotcom/go/namecom"
     9  
    10  	"github.com/StackExchange/dnscontrol/v2/providers"
    11  )
    12  
    13  const defaultAPIBase = "api.name.com"
    14  
    15  // NameCom describes a connection to the NDC API.
    16  type NameCom struct {
    17  	APIUrl  string `json:"apiurl"`
    18  	APIUser string `json:"apiuser"`
    19  	APIKey  string `json:"apikey"`
    20  	client  *namecom.NameCom
    21  }
    22  
    23  var features = providers.DocumentationNotes{
    24  	providers.CanUseAlias:            providers.Can(),
    25  	providers.CanUsePTR:              providers.Cannot("PTR records are not supported (See Link)", "https://www.name.com/support/articles/205188508-Reverse-DNS-records"),
    26  	providers.CanUseSRV:              providers.Can("SRV records with empty targets are not supported"),
    27  	providers.CanUseTXTMulti:         providers.Cannot(),
    28  	providers.DocCreateDomains:       providers.Cannot("New domains require registration"),
    29  	providers.DocDualHost:            providers.Cannot("Apex NS records not editable"),
    30  	providers.DocOfficiallySupported: providers.Can(),
    31  	providers.CanGetZones:            providers.Can(),
    32  }
    33  
    34  func newReg(conf map[string]string) (providers.Registrar, error) {
    35  	return newProvider(conf)
    36  }
    37  
    38  func newDsp(conf map[string]string, meta json.RawMessage) (providers.DNSServiceProvider, error) {
    39  	return newProvider(conf)
    40  }
    41  
    42  func newProvider(conf map[string]string) (*NameCom, error) {
    43  	api := &NameCom{
    44  		client: namecom.New(conf["apiuser"], conf["apikey"]),
    45  	}
    46  	api.client.Server = conf["apiurl"]
    47  	api.APIUser, api.APIKey, api.APIUrl = conf["apiuser"], conf["apikey"], conf["apiurl"]
    48  	if api.APIKey == "" || api.APIUser == "" {
    49  		return nil, fmt.Errorf("missing Name.com apikey or apiuser")
    50  	}
    51  	if api.APIUrl == "" {
    52  		api.APIUrl = defaultAPIBase
    53  	}
    54  	return api, nil
    55  }
    56  
    57  func init() {
    58  	providers.RegisterRegistrarType("NAMEDOTCOM", newReg)
    59  	providers.RegisterDomainServiceProviderType("NAMEDOTCOM", newDsp, features)
    60  }