1
0
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:
Mike Cochrane
2020-09-05 02:22:41 +12:00
committed by GitHub
parent faac40cbf4
commit d6f3f401a5
7 changed files with 168 additions and 0 deletions

36
providers/doh/api.go Normal file
View 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)
}

View 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
}