mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-02-24 23:53:01 +08:00
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
package zonerecs
|
|
|
|
import (
|
|
"github.com/StackExchange/dnscontrol/v4/models"
|
|
"github.com/go-acme/lego/v4/log"
|
|
)
|
|
|
|
// CorrectZoneRecords calls both GetZoneRecords, does any
|
|
// post-processing, and then calls GetZoneRecordsCorrections. The
|
|
// name sucks because all the good names were taken.
|
|
func CorrectZoneRecords(driver models.DNSProvider, dc *models.DomainConfig) ([]*models.Correction, []*models.Correction, int, error) {
|
|
existingRecords, err := driver.GetZoneRecords(dc.Name, dc.Metadata)
|
|
if err != nil {
|
|
return nil, nil, 0, err
|
|
}
|
|
|
|
if models.CheckAndFixImport(existingRecords, dc.Name) {
|
|
log.Warnf("Domain %+v sent records not yet converted to new-style Fields storage. Adjusting.", dc.DNSProviderNames)
|
|
}
|
|
|
|
// downcase
|
|
models.Downcase(existingRecords)
|
|
models.Downcase(dc.Records)
|
|
models.CanonicalizeTargets(existingRecords, dc.Name)
|
|
models.CanonicalizeTargets(dc.Records, dc.Name)
|
|
|
|
// Copy dc so that any corrections code that wants to
|
|
// modify the records may. For example, if the provider only
|
|
// supports certain TTL values, it will adjust the ones in
|
|
// dc.Records.
|
|
dc, err = dc.Copy()
|
|
if err != nil {
|
|
return nil, nil, 0, err
|
|
}
|
|
|
|
// punycode
|
|
if err := dc.Punycode(); err != nil {
|
|
return nil, nil, 0, err
|
|
}
|
|
// FIXME(tlim) It is a waste to PunyCode every iteration.
|
|
// This should be moved to where the JavaScript is processed.
|
|
|
|
everything, actualChangeCount, err := driver.GetZoneRecordsCorrections(dc, existingRecords)
|
|
reports, corrections := splitReportsAndCorrections(everything)
|
|
return reports, corrections, actualChangeCount, err
|
|
}
|
|
|
|
func splitReportsAndCorrections(everything []*models.Correction) (reports, corrections []*models.Correction) {
|
|
for i := range everything {
|
|
if everything[i].F == nil {
|
|
reports = append(reports, everything[i])
|
|
} else {
|
|
corrections = append(corrections, everything[i])
|
|
}
|
|
}
|
|
return reports, corrections
|
|
}
|