HEDNS: Adopt diff2 in compatibility mode (#1887)

This commit is contained in:
Tom Limoncelli 2023-01-02 08:25:23 -05:00 committed by GitHub
parent e0fef398be
commit f8fd853a02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -205,53 +205,52 @@ func (c *hednsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models
txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
var corrections []*models.Correction var corrections []*models.Correction
if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives var toCreate, toDelete, toModify diff.Changeset
if !diff2.EnableDiff2 {
differ := diff.New(dc) differ := diff.New(dc)
_, toCreate, toDelete, toModify, err := differ.IncrementalDiff(prunedRecords) _, toCreate, toDelete, toModify, err = differ.IncrementalDiff(prunedRecords)
if err != nil { } else {
return nil, err differ := diff.NewCompat(dc)
} _, toCreate, toDelete, toModify, err = differ.IncrementalDiff(prunedRecords)
}
for _, del := range toDelete { if err != nil {
record := del.Existing return nil, err
corrections = append(corrections, &models.Correction{
Msg: del.String(),
F: func() error { return c.deleteZoneRecord(record) },
})
}
for _, cre := range toCreate {
record := cre.Desired
record.Original = Record{
ZoneName: dc.Name,
ZoneID: zoneID,
RecordName: cre.Desired.Name,
}
corrections = append(corrections, &models.Correction{
Msg: cre.String(),
F: func() error { return c.editZoneRecord(record, true) },
})
}
for _, mod := range toModify {
record := mod.Desired
record.Original = Record{
ZoneName: dc.Name,
ZoneID: zoneID,
RecordID: mod.Existing.Original.(Record).RecordID,
RecordName: mod.Desired.Name,
}
corrections = append(corrections, &models.Correction{
Msg: mod.String(),
F: func() error { return c.editZoneRecord(record, false) },
})
}
return corrections, err
} }
// Insert Future diff2 version here. for _, del := range toDelete {
record := del.Existing
corrections = append(corrections, &models.Correction{
Msg: del.String(),
F: func() error { return c.deleteZoneRecord(record) },
})
}
for _, cre := range toCreate {
record := cre.Desired
record.Original = Record{
ZoneName: dc.Name,
ZoneID: zoneID,
RecordName: cre.Desired.Name,
}
corrections = append(corrections, &models.Correction{
Msg: cre.String(),
F: func() error { return c.editZoneRecord(record, true) },
})
}
for _, mod := range toModify {
record := mod.Desired
record.Original = Record{
ZoneName: dc.Name,
ZoneID: zoneID,
RecordID: mod.Existing.Original.(Record).RecordID,
RecordName: mod.Desired.Name,
}
corrections = append(corrections, &models.Correction{
Msg: mod.String(),
F: func() error { return c.editZoneRecord(record, false) },
})
}
return corrections, nil return corrections, nil
} }