mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
NEW PROVIDER: DOH: Read-only Registrar that validates NS records (#840)
This commit is contained in:
36
providers/doh/api.go
Normal file
36
providers/doh/api.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package doh
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/babolivier/go-doh-client"
|
||||
)
|
||||
|
||||
type api struct {
|
||||
host string
|
||||
}
|
||||
|
||||
func (c *api) getNameservers(domain string) ([]string, error) {
|
||||
resolver := doh.Resolver{
|
||||
Host: c.host,
|
||||
Class: doh.IN,
|
||||
}
|
||||
|
||||
// Perform a NS lookup
|
||||
nss, _, err := resolver.LookupNS(domain)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed fetching nameservers list (DNS-over-HTTPS): %s", err)
|
||||
}
|
||||
|
||||
ns := []string{}
|
||||
for _, res := range nss {
|
||||
ns = append(ns, res.Host)
|
||||
}
|
||||
sort.Strings(ns)
|
||||
return ns, nil
|
||||
}
|
||||
|
||||
func (c *api) updateNameservers(ns []string, domain string) error {
|
||||
return fmt.Errorf("DNS-over-HTTPS 'Registrar' is read only, changes must be applied to %s manually", domain)
|
||||
}
|
61
providers/doh/dohProvider.go
Normal file
61
providers/doh/dohProvider.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package doh
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v3/models"
|
||||
"github.com/StackExchange/dnscontrol/v3/providers"
|
||||
)
|
||||
|
||||
/*
|
||||
|
||||
DNS over HTTPS 'Registrar':
|
||||
|
||||
Info required in `creds.json`:
|
||||
- host DNS over HTTPS host (eg 9.9.9.9)
|
||||
*/
|
||||
|
||||
func init() {
|
||||
providers.RegisterRegistrarType("DNSOVERHTTPS", newDNSOverHTTPS)
|
||||
}
|
||||
|
||||
func newDNSOverHTTPS(m map[string]string) (providers.Registrar, error) {
|
||||
api := &api{
|
||||
host: m["host"],
|
||||
}
|
||||
if api.host == "" {
|
||||
api.host = "dns.google"
|
||||
}
|
||||
return api, nil
|
||||
}
|
||||
|
||||
// GetRegistrarCorrections gathers corrections that would being n to match dc.
|
||||
func (c *api) GetRegistrarCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
||||
nss, err := c.getNameservers(dc.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
foundNameservers := strings.Join(nss, ",")
|
||||
|
||||
expected := []string{}
|
||||
for _, ns := range dc.Nameservers {
|
||||
expected = append(expected, ns.Name)
|
||||
}
|
||||
sort.Strings(expected)
|
||||
expectedNameservers := strings.Join(expected, ",")
|
||||
|
||||
if foundNameservers == expectedNameservers {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return []*models.Correction{
|
||||
{
|
||||
Msg: fmt.Sprintf("Update nameservers %s -> %s", foundNameservers, expectedNameservers),
|
||||
F: func() error {
|
||||
return c.updateNameservers(expected, dc.Name)
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
Reference in New Issue
Block a user