mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
BUG: Some DNS zones are downloaded twice (#2120)
Signed-off-by: Amelia Aronsohn <squirrel@wearing.black> Co-authored-by: Tom Limoncelli <tal@whatexit.org> Co-authored-by: Grégoire Henry <hnrgrgr@users.noreply.github.com> Co-authored-by: Amelia Aronsohn <squirrel@wearing.black> Co-authored-by: Kai Schwarz <kschwarz@hexonet.net> Co-authored-by: Asif Nawaz <asif.nawaz@centralnic.com> Co-authored-by: imlonghao <git@imlonghao.com> Co-authored-by: Will Power <1619102+willpower232@users.noreply.github.com>
This commit is contained in:
@@ -53,6 +53,9 @@ type gcloudProvider struct {
|
||||
project string
|
||||
nameServerSet *string
|
||||
zones map[string]*gdns.ManagedZone
|
||||
// diff1
|
||||
oldRRsMap map[string]map[key]*gdns.ResourceRecordSet
|
||||
zoneNameMap map[string]string
|
||||
}
|
||||
|
||||
type errNoExist struct {
|
||||
@@ -105,6 +108,8 @@ func New(cfg map[string]string, metadata json.RawMessage) (providers.DNSServiceP
|
||||
client: dcli,
|
||||
nameServerSet: nss,
|
||||
project: cfg["project_id"],
|
||||
oldRRsMap: map[string]map[key]*gdns.ResourceRecordSet{},
|
||||
zoneNameMap: map[string]string{},
|
||||
}
|
||||
return g, g.loadZoneInfo()
|
||||
}
|
||||
@@ -168,14 +173,14 @@ func keyForRec(r *models.RecordConfig) key {
|
||||
|
||||
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
|
||||
func (g *gcloudProvider) GetZoneRecords(domain string) (models.Records, error) {
|
||||
existingRecords, _, _, err := g.getZoneSets(domain)
|
||||
existingRecords, err := g.getZoneSets(domain)
|
||||
return existingRecords, err
|
||||
}
|
||||
|
||||
func (g *gcloudProvider) getZoneSets(domain string) (models.Records, map[key]*gdns.ResourceRecordSet, string, error) {
|
||||
func (g *gcloudProvider) getZoneSets(domain string) (models.Records, error) {
|
||||
rrs, zoneName, err := g.getRecords(domain)
|
||||
if err != nil {
|
||||
return nil, nil, "", err
|
||||
return nil, err
|
||||
}
|
||||
// convert to dnscontrol RecordConfig format
|
||||
existingRecords := []*models.RecordConfig{}
|
||||
@@ -185,28 +190,33 @@ func (g *gcloudProvider) getZoneSets(domain string) (models.Records, map[key]*gd
|
||||
for _, rec := range set.Rrdatas {
|
||||
rt, err := nativeToRecord(set, rec, domain)
|
||||
if err != nil {
|
||||
return nil, nil, "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
existingRecords = append(existingRecords, rt)
|
||||
}
|
||||
}
|
||||
return existingRecords, oldRRs, zoneName, err
|
||||
|
||||
g.oldRRsMap[domain] = oldRRs
|
||||
g.zoneNameMap[domain] = zoneName
|
||||
|
||||
return existingRecords, err
|
||||
}
|
||||
|
||||
func (g *gcloudProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
||||
if err := dc.Punycode(); err != nil {
|
||||
return nil, fmt.Errorf("punycode error: %w", err)
|
||||
}
|
||||
existingRecords, oldRRs, zoneName, err := g.getZoneSets(dc.Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getzonesets error: %w", err)
|
||||
}
|
||||
// GetZoneRecordsCorrections returns a list of corrections that will turn existing records into dc.Records.
|
||||
func (g *gcloudProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) {
|
||||
|
||||
// Normalize
|
||||
models.PostProcessRecords(existingRecords)
|
||||
txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
|
||||
|
||||
oldRRs, ok := g.oldRRsMap[dc.Name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("oldRRsMap: no zone named %q", dc.Name)
|
||||
}
|
||||
zoneName, ok := g.zoneNameMap[dc.Name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("zoneNameMap: no zone named %q", dc.Name)
|
||||
}
|
||||
|
||||
// first collect keys that have changed
|
||||
var differ diff.Differ
|
||||
if !diff2.EnableDiff2 {
|
||||
|
Reference in New Issue
Block a user