github.com/karsthammer/dnscontrol@v0.2.8/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  
     7  	"github.com/StackExchange/dnscontrol/providers"
     8  	"github.com/namedotcom/go/namecom"
     9  	"github.com/pkg/errors"
    10  )
    11  
    12  const defaultAPIBase = "api.name.com"
    13  
    14  // NameCom describes a connection to the NDC API.
    15  type NameCom struct {
    16  	APIUrl  string `json:"apiurl"`
    17  	APIUser string `json:"apiuser"`
    18  	APIKey  string `json:"apikey"`
    19  	client  *namecom.NameCom
    20  }
    21  
    22  var features = providers.DocumentationNotes{
    23  	providers.CanUseAlias:            providers.Can(),
    24  	providers.CanUsePTR:              providers.Cannot("PTR records are not supported (See Link)", "https://www.name.com/support/articles/205188508-Reverse-DNS-records"),
    25  	providers.CanUseSRV:              providers.Can(),
    26  	providers.CanUseTXTMulti:         providers.Can(),
    27  	providers.DocCreateDomains:       providers.Cannot("New domains require registration"),
    28  	providers.DocDualHost:            providers.Cannot("Apex NS records not editable"),
    29  	providers.DocOfficiallySupported: providers.Can(),
    30  }
    31  
    32  func newReg(conf map[string]string) (providers.Registrar, error) {
    33  	return newProvider(conf)
    34  }
    35  
    36  func newDsp(conf map[string]string, meta json.RawMessage) (providers.DNSServiceProvider, error) {
    37  	return newProvider(conf)
    38  }
    39  
    40  func newProvider(conf map[string]string) (*NameCom, error) {
    41  	api := &NameCom{
    42  		client: namecom.New(conf["apiuser"], conf["apikey"]),
    43  	}
    44  	api.client.Server = conf["apiurl"]
    45  	api.APIUser, api.APIKey, api.APIUrl = conf["apiuser"], conf["apikey"], conf["apiurl"]
    46  	if api.APIKey == "" || api.APIUser == "" {
    47  		return nil, errors.Errorf("missing Name.com apikey or apiuser")
    48  	}
    49  	if api.APIUrl == "" {
    50  		api.APIUrl = defaultAPIBase
    51  	}
    52  	return api, nil
    53  }
    54  
    55  func init() {
    56  	providers.RegisterRegistrarType("NAMEDOTCOM", newReg)
    57  	providers.RegisterDomainServiceProviderType("NAMEDOTCOM", newDsp, features)
    58  }