DOMAINNAMESHOP: Adopt diff2 in compatibility mode (#1880)

This commit is contained in:
Tom Limoncelli 2023-01-01 22:44:05 -05:00 committed by GitHub
parent bec7e1e865
commit e0fef398be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,66 +48,65 @@ func (api *domainNameShopProvider) GetDomainCorrections(dc *models.DomainConfig)
}
var corrections []*models.Correction
if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives
var create, delete, modify diff.Changeset
if !diff2.EnableDiff2 {
differ := diff.New(dc)
_, create, delete, modify, err := differ.IncrementalDiff(existingRecords)
_, create, delete, modify, err = differ.IncrementalDiff(existingRecords)
} else {
differ := diff.NewCompat(dc)
_, create, delete, modify, err = differ.IncrementalDiff(existingRecords)
}
if err != nil {
return nil, err
}
// Delete record
for _, r := range delete {
domainID := r.Existing.Original.(*domainNameShopRecord).DomainID
recordID := strconv.Itoa(r.Existing.Original.(*domainNameShopRecord).ID)
corr := &models.Correction{
Msg: fmt.Sprintf("%s, record id: %s", r.String(), recordID),
F: func() error { return api.deleteRecord(domainID, recordID) },
}
corrections = append(corrections, corr)
}
// Create records
for _, r := range create {
// Retrieve the domain name that is targeted. I.e. example.com instead of sub.example.com
domainName := strings.Replace(r.Desired.GetLabelFQDN(), r.Desired.GetLabel()+".", "", -1)
dnsR, err := api.fromRecordConfig(domainName, r.Desired)
if err != nil {
return nil, err
}
// Delete record
for _, r := range delete {
domainID := r.Existing.Original.(*domainNameShopRecord).DomainID
recordID := strconv.Itoa(r.Existing.Original.(*domainNameShopRecord).ID)
corr := &models.Correction{
Msg: fmt.Sprintf("%s, record id: %s", r.String(), recordID),
F: func() error { return api.deleteRecord(domainID, recordID) },
}
corrections = append(corrections, corr)
corr := &models.Correction{
Msg: r.String(),
F: func() error { return api.CreateRecord(domainName, dnsR) },
}
// Create records
for _, r := range create {
// Retrieve the domain name that is targeted. I.e. example.com instead of sub.example.com
domainName := strings.Replace(r.Desired.GetLabelFQDN(), r.Desired.GetLabel()+".", "", -1)
dnsR, err := api.fromRecordConfig(domainName, r.Desired)
if err != nil {
return nil, err
}
corr := &models.Correction{
Msg: r.String(),
F: func() error { return api.CreateRecord(domainName, dnsR) },
}
corrections = append(corrections, corr)
}
for _, r := range modify {
domainName := strings.Replace(r.Desired.GetLabelFQDN(), r.Desired.GetLabel()+".", "", -1)
dnsR, err := api.fromRecordConfig(domainName, r.Desired)
if err != nil {
return nil, err
}
dnsR.ID = r.Existing.Original.(*domainNameShopRecord).ID
corr := &models.Correction{
Msg: r.String(),
F: func() error { return api.UpdateRecord(dnsR) },
}
corrections = append(corrections, corr)
}
return corrections, nil
corrections = append(corrections, corr)
}
// Insert Future diff2 version here.
for _, r := range modify {
domainName := strings.Replace(r.Desired.GetLabelFQDN(), r.Desired.GetLabel()+".", "", -1)
dnsR, err := api.fromRecordConfig(domainName, r.Desired)
if err != nil {
return nil, err
}
dnsR.ID = r.Existing.Original.(*domainNameShopRecord).ID
corr := &models.Correction{
Msg: r.String(),
F: func() error { return api.UpdateRecord(dnsR) },
}
corrections = append(corrections, corr)
}
return corrections, nil
}