mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Refactor: Prelink providers to domains (#305)
This commit is contained in:
committed by
Tom Limoncelli
parent
b7c6efaa53
commit
7a4dca5ad5
@@ -246,30 +246,19 @@ type Warning struct {
|
||||
|
||||
// NormalizeAndValidateConfig performs and normalization and/or validation of the IR.
|
||||
func NormalizeAndValidateConfig(config *models.DNSConfig) (errs []error) {
|
||||
ptypeMap := map[string]string{}
|
||||
for _, p := range config.DNSProviders {
|
||||
ptypeMap[p.Name] = p.Type
|
||||
}
|
||||
|
||||
for _, domain := range config.Domains {
|
||||
pTypes := []string{}
|
||||
txtMultiDissenters := []string{}
|
||||
for p := range domain.DNSProviders {
|
||||
pType, ok := ptypeMap[p]
|
||||
if !ok {
|
||||
errs = append(errs, fmt.Errorf("%s uses undefined DNS provider %s", domain.Name, p))
|
||||
} else {
|
||||
pTypes = append(pTypes, pType)
|
||||
}
|
||||
|
||||
for _, provider := range domain.DNSProviderInstances {
|
||||
pType := provider.ProviderType
|
||||
// If NO_PURGE is in use, make sure this *isn't* a provider that *doesn't* support NO_PURGE.
|
||||
if domain.KeepUnknown && providers.ProviderHasCabability(pType, providers.CantUseNOPURGE) {
|
||||
errs = append(errs, fmt.Errorf("%s uses NO_PURGE which is not supported by %s(%s)", domain.Name, p, pType))
|
||||
errs = append(errs, fmt.Errorf("%s uses NO_PURGE which is not supported by %s(%s)", domain.Name, provider.Name, pType))
|
||||
}
|
||||
|
||||
// Record if any providers do not support TXTMulti:
|
||||
if !providers.ProviderHasCabability(pType, providers.CanUseTXTMulti) {
|
||||
txtMultiDissenters = append(txtMultiDissenters, p)
|
||||
txtMultiDissenters = append(txtMultiDissenters, provider.Name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,7 +363,7 @@ func NormalizeAndValidateConfig(config *models.DNSConfig) (errs []error) {
|
||||
|
||||
// Check that if any aliases / ptr / etc.. are used in a domain, every provider for that domain supports them
|
||||
for _, d := range config.Domains {
|
||||
err := checkProviderCapabilities(d, config.DNSProviders)
|
||||
err := checkProviderCapabilities(d)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
@@ -401,7 +390,7 @@ func checkCNAMEs(dc *models.DomainConfig) (errs []error) {
|
||||
return
|
||||
}
|
||||
|
||||
func checkProviderCapabilities(dc *models.DomainConfig, pList []*models.DNSProviderConfig) error {
|
||||
func checkProviderCapabilities(dc *models.DomainConfig) error {
|
||||
types := []struct {
|
||||
rType string
|
||||
cap providers.Capability
|
||||
@@ -423,14 +412,9 @@ func checkProviderCapabilities(dc *models.DomainConfig, pList []*models.DNSProvi
|
||||
if !hasAny {
|
||||
continue
|
||||
}
|
||||
for pName := range dc.DNSProviders {
|
||||
for _, p := range pList {
|
||||
if p.Name == pName {
|
||||
if !providers.ProviderHasCabability(p.Type, ty.cap) {
|
||||
return fmt.Errorf("Domain %s uses %s records, but DNS provider type %s does not support them", dc.Name, ty.rType, p.Type)
|
||||
}
|
||||
break
|
||||
}
|
||||
for _, provider := range dc.DNSProviderInstances {
|
||||
if !providers.ProviderHasCabability(provider.ProviderType, ty.cap) {
|
||||
return fmt.Errorf("Domain %s uses %s records, but DNS provider type %s does not support them", dc.Name, ty.rType, provider.ProviderType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user