github.com/StackExchange/DNSControl@v0.2.8/providers/hexonet/hexonetProvider.go (about)

     1  // Package hexonet implements a registrar that uses the hexonet api to set name servers. It will self register it's providers when imported.
     2  package hexonet
     3  
     4  import (
     5  	"encoding/json"
     6  	"fmt"
     7  
     8  	"github.com/StackExchange/dnscontrol/providers"
     9  	hxcl "github.com/hexonet/go-sdk/client"
    10  )
    11  
    12  // HXClient describes a connection to the hexonet API.
    13  type HXClient struct {
    14  	APILogin    string
    15  	APIPassword string
    16  	APIEntity   string
    17  	client      *hxcl.Client
    18  }
    19  
    20  var features = providers.DocumentationNotes{
    21  	providers.CanUseAlias:            providers.Cannot("Using ALIAS is possible through our extended DNS (X-DNS) service. Feel free to get in touch with us."),
    22  	providers.CanUseCAA:              providers.Can(),
    23  	providers.CanUsePTR:              providers.Can(),
    24  	providers.CanUseRoute53Alias:     providers.Cannot("Using ALIAS is possible through our extended DNS (X-DNS) service. Feel free to get in touch with us."),
    25  	providers.CanUseSRV:              providers.Can(),
    26  	providers.CanUseTLSA:             providers.Can(),
    27  	providers.CanUseTXTMulti:         providers.Can(),
    28  	providers.CantUseNOPURGE:         providers.Can(),
    29  	providers.DocCreateDomains:       providers.Can(),
    30  	providers.DocDualHost:            providers.Can(),
    31  	providers.DocOfficiallySupported: providers.Cannot("Actively maintained provider module."),
    32  }
    33  
    34  func newProvider(conf map[string]string) (*HXClient, error) {
    35  	api := &HXClient{
    36  		client: hxcl.NewClient(),
    37  	}
    38  	api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"]
    39  	if conf["debugmode"] == "1" {
    40  		api.client.EnableDebugMode()
    41  	}
    42  	if len(conf["ipaddress"]) > 0 {
    43  		api.client.SetIPAddress(conf["ipaddress"])
    44  	}
    45  	if api.APIEntity != "OTE" && api.APIEntity != "LIVE" {
    46  		return nil, fmt.Errorf("wrong api system entity used. use \"OTE\" for OT&E system or \"LIVE\" for Live system")
    47  	}
    48  	if api.APIEntity == "OTE" {
    49  		api.client.UseOTESystem()
    50  	}
    51  	if api.APILogin == "" || api.APIPassword == "" {
    52  		return nil, fmt.Errorf("missing login credentials apilogin or apipassword")
    53  	}
    54  	api.client.SetCredentials(api.APILogin, api.APIPassword, "")
    55  	return api, nil
    56  }
    57  
    58  func newReg(conf map[string]string) (providers.Registrar, error) {
    59  	return newProvider(conf)
    60  }
    61  
    62  func newDsp(conf map[string]string, meta json.RawMessage) (providers.DNSServiceProvider, error) {
    63  	return newProvider(conf)
    64  }
    65  
    66  func init() {
    67  	providers.RegisterRegistrarType("HEXONET", newReg)
    68  	providers.RegisterDomainServiceProviderType("HEXONET", newDsp, features)
    69  }