diff --git a/providers/domainnameshop/dns.go b/providers/domainnameshop/dns.go index 432582266..b0a2f826c 100644 --- a/providers/domainnameshop/dns.go +++ b/providers/domainnameshop/dns.go @@ -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 }