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"
|
|
|
|
|
2020-10-12 23:45:44 +08:00
|
|
|
"github.com/StackExchange/dnscontrol/v3/pkg/version"
|
2020-04-15 04:47:30 +08:00
|
|
|
"github.com/StackExchange/dnscontrol/v3/providers"
|
2021-04-13 19:30:32 +08:00
|
|
|
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
|
2020-02-28 02:04:17 +08:00
|
|
|
client *hxcl.APIClient
|
2018-08-30 20:54:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var features = providers.DocumentationNotes{
|
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."),
|
2020-02-28 12:06:12 +08:00
|
|
|
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{
|
2020-02-28 02:04:17 +08:00
|
|
|
client: hxcl.NewAPIClient(),
|
2018-08-30 20:54:42 +08:00
|
|
|
}
|
2020-10-19 02:04:50 +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 {
|
2020-02-28 02:04:17 +08:00
|
|
|
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")
|
|
|
|
}
|
2020-02-28 02:04:17 +08:00
|
|
|
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() {
|
2021-03-08 02:19:22 +08:00
|
|
|
fns := providers.DspFuncs{
|
2021-05-05 02:15:31 +08:00
|
|
|
Initializer: newDsp,
|
2021-03-09 09:14:30 +08:00
|
|
|
RecordAuditor: AuditRecords,
|
2021-03-08 02:19:22 +08:00
|
|
|
}
|
2018-08-30 20:54:42 +08:00
|
|
|
providers.RegisterRegistrarType("HEXONET", newReg)
|
2021-03-08 02:19:22 +08:00
|
|
|
providers.RegisterDomainServiceProviderType("HEXONET", fns, features)
|
2018-08-30 20:54:42 +08:00
|
|
|
}
|