mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-10-10 05:46:17 +08:00
DIGITALOCEAN: Adopt diff2 in compatibility mode (#1877)
This commit is contained in:
parent
f8fd853a02
commit
cc132b7268
1 changed files with 62 additions and 63 deletions
|
@ -147,72 +147,71 @@ func (api *digitaloceanProvider) GetDomainCorrections(dc *models.DomainConfig) (
|
||||||
txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
|
txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
|
||||||
|
|
||||||
var corrections []*models.Correction
|
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)
|
differ := diff.New(dc)
|
||||||
_, create, delete, modify, err := differ.IncrementalDiff(existingRecords)
|
_, create, delete, modify, err = differ.IncrementalDiff(existingRecords)
|
||||||
if err != nil {
|
} else {
|
||||||
return nil, err
|
differ := diff.NewCompat(dc)
|
||||||
}
|
_, create, delete, modify, err = differ.IncrementalDiff(existingRecords)
|
||||||
|
}
|
||||||
// Deletes first so changing type works etc.
|
if err != nil {
|
||||||
for _, m := range delete {
|
return nil, err
|
||||||
id := m.Existing.Original.(*godo.DomainRecord).ID
|
|
||||||
corr := &models.Correction{
|
|
||||||
Msg: fmt.Sprintf("%s, DO ID: %d", m.String(), id),
|
|
||||||
F: func() error {
|
|
||||||
retry:
|
|
||||||
resp, err := api.client.Domains.DeleteRecord(ctx, dc.Name, id)
|
|
||||||
if err != nil {
|
|
||||||
if pauseAndRetry(resp) {
|
|
||||||
goto retry
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
},
|
|
||||||
}
|
|
||||||
corrections = append(corrections, corr)
|
|
||||||
}
|
|
||||||
for _, m := range create {
|
|
||||||
req := toReq(dc, m.Desired)
|
|
||||||
corr := &models.Correction{
|
|
||||||
Msg: m.String(),
|
|
||||||
F: func() error {
|
|
||||||
retry:
|
|
||||||
_, resp, err := api.client.Domains.CreateRecord(ctx, dc.Name, req)
|
|
||||||
if err != nil {
|
|
||||||
if pauseAndRetry(resp) {
|
|
||||||
goto retry
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
},
|
|
||||||
}
|
|
||||||
corrections = append(corrections, corr)
|
|
||||||
}
|
|
||||||
for _, m := range modify {
|
|
||||||
id := m.Existing.Original.(*godo.DomainRecord).ID
|
|
||||||
req := toReq(dc, m.Desired)
|
|
||||||
corr := &models.Correction{
|
|
||||||
Msg: fmt.Sprintf("%s, DO ID: %d", m.String(), id),
|
|
||||||
F: func() error {
|
|
||||||
retry:
|
|
||||||
_, resp, err := api.client.Domains.EditRecord(ctx, dc.Name, id, req)
|
|
||||||
if err != nil {
|
|
||||||
if pauseAndRetry(resp) {
|
|
||||||
goto retry
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
},
|
|
||||||
}
|
|
||||||
corrections = append(corrections, corr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return corrections, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert Future diff2 version here.
|
// Deletes first so changing type works etc.
|
||||||
|
for _, m := range delete {
|
||||||
|
id := m.Existing.Original.(*godo.DomainRecord).ID
|
||||||
|
corr := &models.Correction{
|
||||||
|
Msg: fmt.Sprintf("%s, DO ID: %d", m.String(), id),
|
||||||
|
F: func() error {
|
||||||
|
retry:
|
||||||
|
resp, err := api.client.Domains.DeleteRecord(ctx, dc.Name, id)
|
||||||
|
if err != nil {
|
||||||
|
if pauseAndRetry(resp) {
|
||||||
|
goto retry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
}
|
||||||
|
corrections = append(corrections, corr)
|
||||||
|
}
|
||||||
|
for _, m := range create {
|
||||||
|
req := toReq(dc, m.Desired)
|
||||||
|
corr := &models.Correction{
|
||||||
|
Msg: m.String(),
|
||||||
|
F: func() error {
|
||||||
|
retry:
|
||||||
|
_, resp, err := api.client.Domains.CreateRecord(ctx, dc.Name, req)
|
||||||
|
if err != nil {
|
||||||
|
if pauseAndRetry(resp) {
|
||||||
|
goto retry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
}
|
||||||
|
corrections = append(corrections, corr)
|
||||||
|
}
|
||||||
|
for _, m := range modify {
|
||||||
|
id := m.Existing.Original.(*godo.DomainRecord).ID
|
||||||
|
req := toReq(dc, m.Desired)
|
||||||
|
corr := &models.Correction{
|
||||||
|
Msg: fmt.Sprintf("%s, DO ID: %d", m.String(), id),
|
||||||
|
F: func() error {
|
||||||
|
retry:
|
||||||
|
_, resp, err := api.client.Domains.EditRecord(ctx, dc.Name, id, req)
|
||||||
|
if err != nil {
|
||||||
|
if pauseAndRetry(resp) {
|
||||||
|
goto retry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
}
|
||||||
|
corrections = append(corrections, corr)
|
||||||
|
}
|
||||||
|
|
||||||
return corrections, nil
|
return corrections, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue