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

CLOUDNS: Adopt diff2 in compatibility mode (#1874)

This commit is contained in:
Tom Limoncelli
2023-02-27 20:16:59 -05:00
committed by GitHub
parent bdeeb2cf1b
commit 4eab96226c

View File

@ -105,89 +105,87 @@ func (c *cloudnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
} }
var corrections []*models.Correction var corrections []*models.Correction
if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives var differ diff.Differ
if !diff2.EnableDiff2 {
differ = diff.New(dc)
} else {
differ = diff.NewCompat(dc)
}
_, create, del, modify, err := differ.IncrementalDiff(existingRecords)
if err != nil {
return nil, err
}
differ := diff.New(dc) // Deletes first so changing type works etc.
_, create, del, modify, err := differ.IncrementalDiff(existingRecords) for _, m := range del {
id := m.Existing.Original.(*domainRecord).ID
corr := &models.Correction{
Msg: fmt.Sprintf("%s, ClouDNS ID: %s", m.String(), id),
F: func() error {
return c.deleteRecord(domainID, id)
},
}
// at ClouDNS, we MUST have a NS for a DS
// So, when deleting, we must delete the DS first, otherwise deleting the NS throws an error
if m.Existing.Type == "DS" {
// type DS is prepended - so executed first
corrections = append([]*models.Correction{corr}, corrections...)
} else {
corrections = append(corrections, corr)
}
}
var createCorrections []*models.Correction
for _, m := range create {
req, err := toReq(m.Desired)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Deletes first so changing type works etc. // ClouDNS does not require the trailing period to be specified when creating an NS record where the A or AAAA record exists in the zone.
for _, m := range del { // So, modify it to remove the trailing period.
id := m.Existing.Original.(*domainRecord).ID if req["record-type"] == "NS" && strings.HasSuffix(req["record"], domainID+".") {
corr := &models.Correction{ req["record"] = strings.TrimSuffix(req["record"], ".")
Msg: fmt.Sprintf("%s, ClouDNS ID: %s", m.String(), id),
F: func() error {
return c.deleteRecord(domainID, id)
},
}
// at ClouDNS, we MUST have a NS for a DS
// So, when deleting, we must delete the DS first, otherwise deleting the NS throws an error
if m.Existing.Type == "DS" {
// type DS is prepended - so executed first
corrections = append([]*models.Correction{corr}, corrections...)
} else {
corrections = append(corrections, corr)
}
} }
var createCorrections []*models.Correction corr := &models.Correction{
for _, m := range create { Msg: m.String(),
req, err := toReq(m.Desired) F: func() error {
if err != nil { return c.createRecord(domainID, req)
return nil, err },
}
// ClouDNS does not require the trailing period to be specified when creating an NS record where the A or AAAA record exists in the zone.
// So, modify it to remove the trailing period.
if req["record-type"] == "NS" && strings.HasSuffix(req["record"], domainID+".") {
req["record"] = strings.TrimSuffix(req["record"], ".")
}
corr := &models.Correction{
Msg: m.String(),
F: func() error {
return c.createRecord(domainID, req)
},
}
// at ClouDNS, we MUST have a NS for a DS
// So, when creating, we must create the NS first, otherwise creating the DS throws an error
if m.Desired.Type == "NS" {
// type NS is prepended - so executed first
createCorrections = append([]*models.Correction{corr}, createCorrections...)
} else {
createCorrections = append(createCorrections, corr)
}
} }
corrections = append(corrections, createCorrections...) // at ClouDNS, we MUST have a NS for a DS
// So, when creating, we must create the NS first, otherwise creating the DS throws an error
for _, m := range modify { if m.Desired.Type == "NS" {
id := m.Existing.Original.(*domainRecord).ID // type NS is prepended - so executed first
req, err := toReq(m.Desired) createCorrections = append([]*models.Correction{corr}, createCorrections...)
if err != nil { } else {
return nil, err createCorrections = append(createCorrections, corr)
}
// ClouDNS does not require the trailing period to be specified when updating an NS record where the A or AAAA record exists in the zone.
// So, modify it to remove the trailing period.
if req["record-type"] == "NS" && strings.HasSuffix(req["record"], domainID+".") {
req["record"] = strings.TrimSuffix(req["record"], ".")
}
corr := &models.Correction{
Msg: fmt.Sprintf("%s, ClouDNS ID: %s: ", m.String(), id),
F: func() error {
return c.modifyRecord(domainID, id, req)
},
}
corrections = append(corrections, corr)
} }
return corrections, nil
} }
corrections = append(corrections, createCorrections...)
// Insert Future diff2 version here. for _, m := range modify {
id := m.Existing.Original.(*domainRecord).ID
req, err := toReq(m.Desired)
if err != nil {
return nil, err
}
// ClouDNS does not require the trailing period to be specified when updating an NS record where the A or AAAA record exists in the zone.
// So, modify it to remove the trailing period.
if req["record-type"] == "NS" && strings.HasSuffix(req["record"], domainID+".") {
req["record"] = strings.TrimSuffix(req["record"], ".")
}
corr := &models.Correction{
Msg: fmt.Sprintf("%s, ClouDNS ID: %s: ", m.String(), id),
F: func() error {
return c.modifyRecord(domainID, id, req)
},
}
corrections = append(corrections, corr)
}
return corrections, nil return corrections, nil