dnscontrol/providers/hexonet/hexonetProvider.go

76 lines
2.7 KiB
Go
Raw Normal View History

2018-08-30 20:54:42 +08:00
// Package hexonet implements a registrar that uses the hexonet api to set name servers. It will self register it's providers when imported.
package hexonet
import (
"encoding/json"
"fmt"
"github.com/StackExchange/dnscontrol/v3/pkg/version"
"github.com/StackExchange/dnscontrol/v3/providers"
hxcl "github.com/hexonet/go-sdk/v3/apiclient"
2018-08-30 20:54:42 +08:00
)
// HXClient describes a connection to the hexonet API.
type HXClient struct {
APILogin string
APIPassword string
APIEntity string
client *hxcl.APIClient
2018-08-30 20:54:42 +08:00
}
var features = providers.DocumentationNotes{
MAINT: Sort various lists (#1433) * maint: sort lists in build/generate/featureMatrix.go * maint: sort lists in docs/byo-secrets.md * maint: sort lists in models/record.go * maint: sort lists in pkg/normalize/validate.go * maint: sort lists in providers/activedir/activedirProvider.go * maint: sort lists in providers/akamaiedgedns/akamaiEdgeDnsProvider.go * maint: sort lists in providers/axfrddns/axfrddnsProvider.go * maint: sort lists in providers/azuredns/azureDnsProvider.go * maint: sort lists in providers/cloudflare/cloudflareProvider.go * maint: sort lists in providers/cloudns/cloudnsProvider.go * maint: sort lists in providers/desec/desecProvider.go * maint: sort lists in providers/digitalocean/digitaloceanProvider.go * maint: sort lists in providers/dnsimple/dnsimpleProvider.go * maint: sort lists in providers/dnsmadeeasy/dnsMadeEasyProvider.go * maint: sort lists in providers/exoscale/exoscaleProvider.go * maint: sort lists in providers/gandiv5/gandi_v5Provider.go * maint: sort lists in providers/hedns/hednsProvider.go * maint: sort lists in providers/hetzner/hetznerProvider.go * maint: sort lists in providers/hexonet/hexonetProvider.go * maint: sort lists in providers/inwx/inwxProvider.go * maint: sort lists in providers/linode/linodeProvider.go * maint: sort lists in providers/namecheap/namecheapProvider.go * maint: sort lists in providers/namedotcom/namedotcomProvider.go * maint: sort lists in providers/netcup/netcupProvider.go * maint: sort lists in providers/ns1/ns1Provider.go * maint: sort lists in providers/octodns/octodnsProvider.go * maint: sort lists in providers/oracle/oracleProvider.go * maint: sort lists in providers/ovh/ovhProvider.go * maint: sort lists in providers/packetframe/packetframeProvider.go * maint: sort lists in providers/powerdns/powerdnsProvider.go * maint: sort lists in providers/route53/route53Provider.go * maint: sort lists in providers/vultr/vultrProvider.go * Update go:build pragmas for windows * More sorting * go generate
2022-03-03 00:19:15 +08:00
providers.CanGetZones: providers.Unimplemented(),
2018-08-30 20:54:42 +08:00
providers.CanUseAlias: providers.Cannot("Using ALIAS is possible through our extended DNS (X-DNS) service. Feel free to get in touch with us."),
providers.CanUseCAA: providers.Can(),
providers.CanUsePTR: providers.Can(),
providers.CanUseRoute53Alias: providers.Cannot("Using ALIAS is possible through our extended DNS (X-DNS) service. Feel free to get in touch with us."),
providers.CanUseSRV: providers.Can("SRV records with empty targets are not supported"),
2018-08-30 20:54:42 +08:00
providers.CanUseTLSA: providers.Can(),
providers.CantUseNOPURGE: providers.Can(),
providers.DocCreateDomains: providers.Can(),
providers.DocDualHost: providers.Can(),
providers.DocOfficiallySupported: providers.Cannot("Actively maintained provider module."),
}
func newProvider(conf map[string]string) (*HXClient, error) {
api := &HXClient{
client: hxcl.NewAPIClient(),
2018-08-30 20:54:42 +08:00
}
api.client.SetUserAgent("DNSControl", version.Banner())
2018-08-30 20:54:42 +08:00
api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"]
if conf["debugmode"] == "1" {
api.client.EnableDebugMode()
}
if len(conf["ipaddress"]) > 0 {
api.client.SetRemoteIPAddress(conf["ipaddress"])
2018-08-30 20:54:42 +08:00
}
if api.APIEntity != "OTE" && api.APIEntity != "LIVE" {
return nil, fmt.Errorf("wrong api system entity used. use \"OTE\" for OT&E system or \"LIVE\" for Live system")
}
if api.APIEntity == "OTE" {
api.client.UseOTESystem()
}
if api.APILogin == "" || api.APIPassword == "" {
return nil, fmt.Errorf("missing login credentials apilogin or apipassword")
}
api.client.SetCredentials(api.APILogin, api.APIPassword)
2018-08-30 20:54:42 +08:00
return api, nil
}
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)
}
func init() {
fns := providers.DspFuncs{
2021-05-05 02:15:31 +08:00
Initializer: newDsp,
RecordAuditor: AuditRecords,
}
2018-08-30 20:54:42 +08:00
providers.RegisterRegistrarType("HEXONET", newReg)
providers.RegisterDomainServiceProviderType("HEXONET", fns, features)
2018-08-30 20:54:42 +08:00
}