1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

NEW FEATURE: Gather data for providers concurrently (#2873)

This commit is contained in:
Tom Limoncelli
2024-03-27 13:54:36 -04:00
committed by GitHub
parent 408a70ec76
commit 68c5e87c89
17 changed files with 933 additions and 67 deletions

View File

@@ -23,15 +23,13 @@ type azurednsProvider struct {
zones map[string]*adns.Zone
resourceGroup *string
subscriptionID *string
rawRecords map[string][]*adns.RecordSet
zoneName map[string]string
}
func newAzureDNSDsp(conf map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
return newAzureDNS(conf, metadata)
}
func newAzureDNS(m map[string]string, metadata json.RawMessage) (*azurednsProvider, error) {
func newAzureDNS(m map[string]string, _ json.RawMessage) (*azurednsProvider, error) {
subID, rg := m["SubscriptionID"], m["ResourceGroup"]
clientID, clientSecret, tenantID := m["ClientID"], m["ClientSecret"], m["TenantID"]
credential, authErr := aauth.NewClientSecretCredential(tenantID, clientID, clientSecret, nil)
@@ -52,8 +50,6 @@ func newAzureDNS(m map[string]string, metadata json.RawMessage) (*azurednsProvid
recordsClient: recordsClient,
resourceGroup: to.StringPtr(rg),
subscriptionID: to.StringPtr(subID),
rawRecords: map[string][]*adns.RecordSet{},
zoneName: map[string]string{},
}
err := api.getZones()
if err != nil {
@@ -66,7 +62,7 @@ var features = providers.DocumentationNotes{
// The default for unlisted capabilities is 'Cannot'.
// See providers/capabilities.go for the entire list of capabilities.
providers.CanGetZones: providers.Can(),
providers.CanConcur: providers.Cannot(),
providers.CanConcur: providers.Can(),
providers.CanUseAlias: providers.Cannot("Azure DNS does not provide a generic ALIAS functionality. Use AZURE_ALIAS instead."),
providers.CanUseAzureAlias: providers.Can(),
providers.CanUseCAA: providers.Can(),
@@ -187,9 +183,6 @@ func (a *azurednsProvider) getExistingRecords(domain string) (models.Records, []
existingRecords = append(existingRecords, nativeToRecords(set, zoneName)...)
}
a.rawRecords[domain] = rawRecords
a.zoneName[domain] = zoneName
return existingRecords, rawRecords, zoneName, nil
}

View File

@@ -2,7 +2,9 @@
package providers
import "log"
import (
"log"
)
// Capability is a bitmasked set of "features" that a provider supports. Only use constants from this package.
type Capability uint32

View File

@@ -8,6 +8,7 @@ import (
"os"
"strconv"
"strings"
"sync"
"golang.org/x/net/idna"
@@ -43,7 +44,7 @@ var features = providers.DocumentationNotes{
// The default for unlisted capabilities is 'Cannot'.
// See providers/capabilities.go for the entire list of capabilities.
providers.CanGetZones: providers.Can(),
providers.CanConcur: providers.Cannot(),
providers.CanConcur: providers.Can(),
providers.CanUseAlias: providers.Can("CF automatically flattens CNAME records into A records dynamically"),
providers.CanUseCAA: providers.Can(),
providers.CanUseDSForChildren: providers.Can(),
@@ -79,6 +80,7 @@ type cloudflareProvider struct {
manageWorkers bool
accountID string
cfClient *cloudflare.API
sync.Mutex
}
// TODO(dlemenkov): remove this function after deleting all commented code referecing it
@@ -94,27 +96,29 @@ type cloudflareProvider struct {
// GetNameservers returns the nameservers for a domain.
func (c *cloudflareProvider) GetNameservers(domain string) ([]*models.Nameserver, error) {
if c.domainIndex == nil {
if err := c.fetchDomainList(); err != nil {
return nil, err
}
if err := c.cacheDomainList(); err != nil {
return nil, err
}
c.Lock()
ns, ok := c.nameservers[domain]
c.Unlock()
if !ok {
return nil, fmt.Errorf("nameservers for %s not found in cloudflare account", domain)
return nil, fmt.Errorf("nameservers for %s not found in cloudflare cache(%q)", domain, c.accountID)
}
return models.ToNameservers(ns)
}
// ListZones returns a list of the DNS zones.
func (c *cloudflareProvider) ListZones() ([]string, error) {
if err := c.fetchDomainList(); err != nil {
if err := c.cacheDomainList(); err != nil {
return nil, err
}
c.Lock()
zones := make([]string, 0, len(c.domainIndex))
for d := range c.domainIndex {
zones = append(zones, d)
}
c.Unlock()
return zones, nil
}
@@ -178,12 +182,12 @@ func (c *cloudflareProvider) GetZoneRecords(domain string, meta map[string]strin
}
func (c *cloudflareProvider) getDomainID(name string) (string, error) {
if c.domainIndex == nil {
if err := c.fetchDomainList(); err != nil {
return "", err
}
if err := c.cacheDomainList(); err != nil {
return "", err
}
c.Lock()
id, ok := c.domainIndex[name]
c.Unlock()
if !ok {
return "", fmt.Errorf("'%s' not a zone in cloudflare account", name)
}
@@ -196,14 +200,6 @@ func (c *cloudflareProvider) GetZoneRecordsCorrections(dc *models.DomainConfig,
if err := c.preprocessConfig(dc); err != nil {
return nil, err
}
// for i := len(records) - 1; i >= 0; i-- {
// rec := records[i]
// // Delete ignore labels
// if labelMatches(dnsutil.TrimDomainName(rec.Original.(cloudflare.DNSRecord).Name, dc.Name), c.ignoredLabels) {
// printer.Debugf("ignored_label: %s\n", rec.Original.(cloudflare.DNSRecord).Name)
// records = append(records[:i], records[i+1:]...)
// }
// }
checkNSModifications(dc)
@@ -222,9 +218,6 @@ func (c *cloudflareProvider) GetZoneRecordsCorrections(dc *models.DomainConfig,
if rec.Metadata[metaProxy] != "off" {
rec.TTL = 1
}
// if labelMatches(rec.GetLabel(), c.ignoredLabels) {
// log.Fatalf("FATAL: dnsconfig contains label that matches ignored_labels: %#v is in %v)\n", rec.GetLabel(), c.ignoredLabels)
// }
}
checkNSModifications(dc)
@@ -815,11 +808,14 @@ func getProxyMetadata(r *models.RecordConfig) map[string]string {
// EnsureZoneExists creates a zone if it does not exist
func (c *cloudflareProvider) EnsureZoneExists(domain string) error {
if c.domainIndex == nil {
if err := c.fetchDomainList(); err != nil {
return err
}
if err := c.cacheDomainList(); err != nil {
return err
}
// if c.domainIndex == nil {
// if err := c.fetchDomainList(); err != nil {
// return err
// }
// }
if _, ok := c.domainIndex[domain]; ok {
return nil
}

View File

@@ -13,7 +13,10 @@ import (
)
// get list of domains for account. Cache so the ids can be looked up from domain name
func (c *cloudflareProvider) fetchDomainList() error {
func (c *cloudflareProvider) cacheDomainList() error {
c.Lock()
defer c.Unlock()
c.domainIndex = map[string]string{}
c.nameservers = map[string][]string{}
zones, err := c.cfClient.ListZones(context.Background())

View File

@@ -28,7 +28,7 @@ var features = providers.DocumentationNotes{
// The default for unlisted capabilities is 'Cannot'.
// See providers/capabilities.go for the entire list of capabilities.
providers.CanGetZones: providers.Can(),
providers.CanConcur: providers.Cannot(),
providers.CanConcur: providers.Can(),
providers.CanUseCAA: providers.Can(),
providers.CanUseSRV: providers.Can(),
providers.DocOfficiallySupported: providers.Can(),

View File

@@ -26,7 +26,7 @@ var features = providers.DocumentationNotes{
// The default for unlisted capabilities is 'Cannot'.
// See providers/capabilities.go for the entire list of capabilities.
providers.CanGetZones: providers.Can(),
providers.CanConcur: providers.Cannot(),
providers.CanConcur: providers.Can(),
providers.CanUseAlias: providers.Can(),
providers.CanUseCAA: providers.Can(),
providers.CanUseDSForChildren: providers.Can(),

View File

@@ -171,10 +171,16 @@ func (n None) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correctio
return nil, nil
}
var featuresNone = DocumentationNotes{
// The default for unlisted capabilities is 'Cannot'.
// See providers/capabilities.go for the entire list of capabilities.
CanConcur: Can(),
}
func init() {
RegisterRegistrarType("NONE", func(map[string]string) (Registrar, error) {
return None{}, nil
})
}, featuresNone)
}
// CustomRType stores an rtype that is only valid for this DSP.

View File

@@ -27,12 +27,11 @@ import (
)
type route53Provider struct {
client *r53.Client
registrar *r53d.Client
delegationSet *string
zonesByID map[string]r53Types.HostedZone
zonesByDomain map[string]r53Types.HostedZone
originalRecords []r53Types.ResourceRecordSet
client *r53.Client
registrar *r53d.Client
delegationSet *string
zonesByID map[string]r53Types.HostedZone
zonesByDomain map[string]r53Types.HostedZone
}
func newRoute53Reg(conf map[string]string) (providers.Registrar, error) {
@@ -79,7 +78,7 @@ var features = providers.DocumentationNotes{
// The default for unlisted capabilities is 'Cannot'.
// See providers/capabilities.go for the entire list of capabilities.
providers.CanGetZones: providers.Can(),
providers.CanConcur: providers.Cannot(),
providers.CanConcur: providers.Can(),
providers.CanUseAlias: providers.Cannot("R53 does not provide a generic ALIAS functionality. Use R53_ALIAS instead."),
providers.CanUseCAA: providers.Can(),
providers.CanUseLOC: providers.Cannot(),
@@ -267,7 +266,6 @@ func (r *route53Provider) getZoneRecords(zone r53Types.HostedZone) (models.Recor
if err != nil {
return nil, err
}
r.originalRecords = records
var existingRecords = []*models.RecordConfig{}
for _, set := range records {