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:
@ -7,6 +7,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/printer"
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/txtutil"
|
||||
"github.com/StackExchange/dnscontrol/v3/providers"
|
||||
@ -176,7 +177,7 @@ func removeOtherApexNS(dc *models.DomainConfig) {
|
||||
}
|
||||
|
||||
func (n *netlifyProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
||||
var corrections []*models.Correction
|
||||
|
||||
err := dc.Punycode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -192,58 +193,66 @@ func (n *netlifyProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
|
||||
txtutil.SplitSingleLongTxt(dc.Records) // Auto split long TXT records
|
||||
removeOtherApexNS(dc)
|
||||
|
||||
differ := diff.New(dc)
|
||||
_, create, del, modify, err := differ.IncrementalDiff(records)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var corrections []*models.Correction
|
||||
if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives
|
||||
|
||||
zone, err := n.getZone(dc.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Deletes first so changing type works etc.
|
||||
for _, m := range del {
|
||||
id := m.Existing.Original.(*dnsRecord).ID
|
||||
corr := &models.Correction{
|
||||
Msg: m.String(),
|
||||
F: func() error {
|
||||
return n.deleteDNSRecord(zone.ID, id)
|
||||
},
|
||||
differ := diff.New(dc)
|
||||
_, create, del, modify, err := differ.IncrementalDiff(records)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
corrections = append(corrections, corr)
|
||||
}
|
||||
|
||||
for _, m := range create {
|
||||
req := toReq(m.Desired)
|
||||
corr := &models.Correction{
|
||||
Msg: m.String(),
|
||||
F: func() error {
|
||||
_, err := n.createDNSRecord(zone.ID, req)
|
||||
return err
|
||||
},
|
||||
zone, err := n.getZone(dc.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
corrections = append(corrections, corr)
|
||||
}
|
||||
|
||||
for _, m := range modify {
|
||||
id := m.Existing.Original.(*dnsRecord).ID
|
||||
req := toReq(m.Desired)
|
||||
corr := &models.Correction{
|
||||
Msg: m.String(),
|
||||
F: func() error {
|
||||
if err := n.deleteDNSRecord(zone.ID, id); err != nil {
|
||||
// Deletes first so changing type works etc.
|
||||
for _, m := range del {
|
||||
id := m.Existing.Original.(*dnsRecord).ID
|
||||
corr := &models.Correction{
|
||||
Msg: m.String(),
|
||||
F: func() error {
|
||||
return n.deleteDNSRecord(zone.ID, id)
|
||||
},
|
||||
}
|
||||
corrections = append(corrections, corr)
|
||||
}
|
||||
|
||||
for _, m := range create {
|
||||
req := toReq(m.Desired)
|
||||
corr := &models.Correction{
|
||||
Msg: m.String(),
|
||||
F: func() error {
|
||||
_, err := n.createDNSRecord(zone.ID, req)
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := n.createDNSRecord(zone.ID, req)
|
||||
return err
|
||||
},
|
||||
},
|
||||
}
|
||||
corrections = append(corrections, corr)
|
||||
}
|
||||
corrections = append(corrections, corr)
|
||||
|
||||
for _, m := range modify {
|
||||
id := m.Existing.Original.(*dnsRecord).ID
|
||||
req := toReq(m.Desired)
|
||||
corr := &models.Correction{
|
||||
Msg: m.String(),
|
||||
F: func() error {
|
||||
if err := n.deleteDNSRecord(zone.ID, id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := n.createDNSRecord(zone.ID, req)
|
||||
return err
|
||||
},
|
||||
}
|
||||
corrections = append(corrections, corr)
|
||||
}
|
||||
|
||||
return corrections, nil
|
||||
}
|
||||
|
||||
// Insert Future diff2 version here.
|
||||
|
||||
return corrections, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user