github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/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/v2/providers" 9 hxcl "github.com/hexonet/go-sdk/apiclient" 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.APIClient 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("SRV records with empty targets are not supported"), 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 providers.CanGetZones: providers.Unimplemented(), 33 } 34 35 func newProvider(conf map[string]string) (*HXClient, error) { 36 api := &HXClient{ 37 client: hxcl.NewAPIClient(), 38 } 39 api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"] 40 if conf["debugmode"] == "1" { 41 api.client.EnableDebugMode() 42 } 43 if len(conf["ipaddress"]) > 0 { 44 api.client.SetRemoteIPAddress(conf["ipaddress"]) 45 } 46 if api.APIEntity != "OTE" && api.APIEntity != "LIVE" { 47 return nil, fmt.Errorf("wrong api system entity used. use \"OTE\" for OT&E system or \"LIVE\" for Live system") 48 } 49 if api.APIEntity == "OTE" { 50 api.client.UseOTESystem() 51 } 52 if api.APILogin == "" || api.APIPassword == "" { 53 return nil, fmt.Errorf("missing login credentials apilogin or apipassword") 54 } 55 api.client.SetCredentials(api.APILogin, api.APIPassword) 56 return api, nil 57 } 58 59 func newReg(conf map[string]string) (providers.Registrar, error) { 60 return newProvider(conf) 61 } 62 63 func newDsp(conf map[string]string, meta json.RawMessage) (providers.DNSServiceProvider, error) { 64 return newProvider(conf) 65 } 66 67 func init() { 68 providers.RegisterRegistrarType("HEXONET", newReg) 69 providers.RegisterDomainServiceProviderType("HEXONET", newDsp, features) 70 }