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

REFACTOR: Add diff2 enable flag to all DNS providers (#1851)

This should enable the diff2 code to be inserted with good "git blame" results for new code.  I'm adding this early to catch any problems early.
This commit is contained in:
Tom Limoncelli
2022-12-11 15:02:58 -05:00
committed by GitHub
parent fe03b29ab2
commit b0f2945510
42 changed files with 2419 additions and 2100 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/StackExchange/dnscontrol/v3/models"
"github.com/StackExchange/dnscontrol/v3/pkg/diff"
"github.com/StackExchange/dnscontrol/v3/pkg/diff2"
"github.com/StackExchange/dnscontrol/v3/pkg/txtutil"
)
@@ -51,44 +52,50 @@ func (api *rwthProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*model
models.PostProcessRecords(existingRecords)
txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
differ := diff.New(dc)
_, create, del, modify, err := differ.IncrementalDiff(existingRecords)
if err != nil {
return nil, err
}
var corrections []*models.Correction
if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives
for _, d := range create {
des := d.Desired
corrections = append(corrections, &models.Correction{
Msg: d.String(),
F: func() error { return api.createRecord(dc.Name, des) },
})
}
for _, d := range del {
existingRecord := d.Existing.Original.(RecordReply)
corrections = append(corrections, &models.Correction{
Msg: d.String(),
F: func() error { return api.destroyRecord(existingRecord) },
})
}
for _, d := range modify {
rec := d.Desired
existingID := d.Existing.Original.(RecordReply).ID
corrections = append(corrections, &models.Correction{
Msg: d.String(),
F: func() error { return api.updateRecord(existingID, *rec) },
})
differ := diff.New(dc)
_, create, del, modify, err := differ.IncrementalDiff(existingRecords)
if err != nil {
return nil, err
}
for _, d := range create {
des := d.Desired
corrections = append(corrections, &models.Correction{
Msg: d.String(),
F: func() error { return api.createRecord(dc.Name, des) },
})
}
for _, d := range del {
existingRecord := d.Existing.Original.(RecordReply)
corrections = append(corrections, &models.Correction{
Msg: d.String(),
F: func() error { return api.destroyRecord(existingRecord) },
})
}
for _, d := range modify {
rec := d.Desired
existingID := d.Existing.Original.(RecordReply).ID
corrections = append(corrections, &models.Correction{
Msg: d.String(),
F: func() error { return api.updateRecord(existingID, *rec) },
})
}
// And deploy if any corrections were applied
if len(corrections) > 0 {
corrections = append(corrections, &models.Correction{
Msg: fmt.Sprintf("Deploy zone %s", domain),
F: func() error { return api.deployZone(domain) },
})
}
return corrections, nil
}
// And deploy if any corrections were applied
if len(corrections) > 0 {
corrections = append(corrections, &models.Correction{
Msg: fmt.Sprintf("Deploy zone %s", domain),
F: func() error { return api.deployZone(domain) },
})
}
// Insert Future diff2 version here.
return corrections, nil
}