mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-10 17:38:13 +08:00
DOMAINNAMESHOP: Adopt diff2 in compatibility mode (#1880)
This commit is contained in:
parent
bec7e1e865
commit
e0fef398be
1 changed files with 50 additions and 51 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue