mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
NS1: Add support for diff2 (#1858)
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
@ -143,6 +143,7 @@ func (n *nsone) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correct
|
|||||||
//dc.CombineMXs()
|
//dc.CombineMXs()
|
||||||
|
|
||||||
domain := dc.Name
|
domain := dc.Name
|
||||||
|
corrections := []*models.Correction{}
|
||||||
|
|
||||||
// Get existing records
|
// Get existing records
|
||||||
existingRecords, err := n.GetZoneRecords(domain)
|
existingRecords, err := n.GetZoneRecords(domain)
|
||||||
@ -150,14 +151,18 @@ func (n *nsone) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correct
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
existingGrouped := existingRecords.GroupedByKey()
|
|
||||||
desiredGrouped := dc.Records.GroupedByKey()
|
|
||||||
|
|
||||||
// Normalize
|
// Normalize
|
||||||
models.PostProcessRecords(existingRecords)
|
models.PostProcessRecords(existingRecords)
|
||||||
|
|
||||||
var corrections []*models.Correction
|
// add DNSSEC-related corrections
|
||||||
if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives
|
if dnssecCorrections := n.getDomainCorrectionsDNSSEC(domain, dc.AutoDNSSEC); dnssecCorrections != nil {
|
||||||
|
corrections = append(corrections, dnssecCorrections)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !diff2.EnableDiff2 {
|
||||||
|
|
||||||
|
existingGrouped := existingRecords.GroupedByKey()
|
||||||
|
desiredGrouped := dc.Records.GroupedByKey()
|
||||||
|
|
||||||
differ := diff.New(dc)
|
differ := diff.New(dc)
|
||||||
changedGroups, err := differ.ChangedGroups(existingRecords)
|
changedGroups, err := differ.ChangedGroups(existingRecords)
|
||||||
@ -165,19 +170,15 @@ func (n *nsone) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correct
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
corrections := []*models.Correction{}
|
|
||||||
|
|
||||||
if dnssecCorrections := n.getDomainCorrectionsDNSSEC(domain, dc.AutoDNSSEC); dnssecCorrections != nil {
|
|
||||||
corrections = append(corrections, dnssecCorrections)
|
|
||||||
}
|
|
||||||
|
|
||||||
// each name/type is given to the api as a unit.
|
// each name/type is given to the api as a unit.
|
||||||
for k, descs := range changedGroups {
|
for k, descs := range changedGroups {
|
||||||
key := k
|
key := k
|
||||||
|
|
||||||
desc := strings.Join(descs, "\n")
|
desc := strings.Join(descs, "\n")
|
||||||
|
|
||||||
_, current := existingGrouped[k]
|
_, current := existingGrouped[k]
|
||||||
recs, wanted := desiredGrouped[k]
|
recs, wanted := desiredGrouped[k]
|
||||||
|
|
||||||
if wanted && !current {
|
if wanted && !current {
|
||||||
// pure addition
|
// pure addition
|
||||||
corrections = append(corrections, &models.Correction{
|
corrections = append(corrections, &models.Correction{
|
||||||
@ -201,8 +202,36 @@ func (n *nsone) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correct
|
|||||||
return corrections, nil
|
return corrections, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert Future diff2 version here.
|
changes, err := diff2.ByRecordSet(existingRecords, dc, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, change := range changes {
|
||||||
|
key := change.Key
|
||||||
|
recs := change.New
|
||||||
|
desc := strings.Join(change.Msgs, "\n")
|
||||||
|
|
||||||
|
if change.Type == diff2.CREATE {
|
||||||
|
corrections = append(corrections, &models.Correction{
|
||||||
|
Msg: desc,
|
||||||
|
F: func() error { return n.add(recs, dc.Name) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if change.Type == diff2.CHANGE {
|
||||||
|
corrections = append(corrections, &models.Correction{
|
||||||
|
Msg: desc,
|
||||||
|
F: func() error { return n.modify(recs, dc.Name) },
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
if change.Type == diff2.DELETE {
|
||||||
|
corrections = append(corrections, &models.Correction{
|
||||||
|
Msg: desc,
|
||||||
|
F: func() error { return n.remove(key, dc.Name) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
return corrections, nil
|
return corrections, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user