VULTR: adopt diff2 in full mode
@@ -134,14 +134,10 @@ func (api *vultrProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
models.PostProcessRecords(curRecords)
var corrections []*models.Correction
- var create, delete, modify diff.Changeset
if !diff2.EnableDiff2 {
differ := diff.New(dc)
- _, create, delete, modify, err = differ.IncrementalDiff(curRecords)
- } else {
- differ := diff.NewCompat(dc)
- _, create, delete, modify, err = differ.IncrementalDiff(curRecords)
- }
+ _, create, delete, modify, err := differ.IncrementalDiff(curRecords)
+
if err != nil {
return nil, err
}
@@ -176,6 +172,44 @@ func (api *vultrProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mode
},
})
}
+ return corrections, nil
+ }
+
+ changes, err := diff2.ByRecord(curRecords, dc, nil)
+
+ if err != nil {
+ return nil, err
+ }
+
+ for _, change := range changes {
+ switch change.Type {
+ case diff2.CREATE:
+ r := toVultrRecord(dc, change.New[0], "0")
+ corrections = append(corrections, &models.Correction{
+ Msg: change.Msgs[0],
+ F: func() error {
+ _, err := api.client.DomainRecord.Create(context.Background(), dc.Name, &govultr.DomainRecordReq{Name: r.Name, Type: r.Type, Data: r.Data, TTL: r.TTL, Priority: &r.Priority})
+ return err
+ },
+ })
+ case diff2.CHANGE:
+ r := toVultrRecord(dc, change.New[0], change.Old[0].Original.(govultr.DomainRecord).ID)
+ corrections = append(corrections, &models.Correction{
+ Msg: fmt.Sprintf("%s; Vultr RecordID: %v", change.Msgs[0], r.ID),
+ F: func() error {
+ return api.client.DomainRecord.Update(context.Background(), dc.Name, r.ID, &govultr.DomainRecordReq{Name: r.Name, Type: r.Type, Data: r.Data, TTL: r.TTL, Priority: &r.Priority})
+ },
+ })
+ case diff2.DELETE:
+ id := change.Old[0].Original.(govultr.DomainRecord).ID
+ corrections = append(corrections, &models.Correction{
+ Msg: fmt.Sprintf("%s; Vultr RecordID: %v", change.Msgs[0], id),
+ F: func() error {
+ return api.client.DomainRecord.Delete(context.Background(), dc.Name, id)
+ },
+ })
+ }
+ }
return corrections, nil
}
