HOSTINGDE: Adopt diff2 in compatibility mode (#1890)

This commit is contained in:
Tom Limoncelli 2023-01-19 13:04:09 -05:00 committed by GitHub
parent e73982c699
commit 8c8d08b72f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 48 deletions

View file

@ -1,10 +1,17 @@
package hostingde
import "github.com/StackExchange/dnscontrol/v3/models"
import (
"github.com/StackExchange/dnscontrol/v3/models"
"github.com/StackExchange/dnscontrol/v3/pkg/rejectif"
)
// AuditRecords returns a list of errors corresponding to the records
// that aren't supported by this provider. If all records are
// supported, an empty list is returned.
func AuditRecords(records []*models.RecordConfig) []error {
return nil
a := rejectif.Auditor{}
a.Add("SRV", rejectif.SrvHasNullTarget) // Last verified 2023-01-19
return a.Audit(records)
}

View file

@ -128,11 +128,13 @@ func (hp *hostingdeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
return nil, err
}
var corrections []*models.Correction
if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives
differ := diff.New(dc)
_, create, del, mod, err := differ.IncrementalDiff(records)
var create, del, mod diff.Changeset
if !diff2.EnableDiff2 {
differ = diff.New(dc)
} else {
differ = diff.NewCompat(dc)
}
_, create, del, mod, err = differ.IncrementalDiff(records)
if err != nil {
return nil, err
}
@ -173,9 +175,24 @@ func (hp *hostingdeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
},
},
}
msg := []string{}
for _, c := range append(del, append(create, mod...)...) {
msg = append(msg, c.String())
}
// Insert Future diff2 version here.
if len(create) == 0 && len(del) == 0 && len(mod) == 0 {
return nil, nil
}
corrections := []*models.Correction{
{
Msg: fmt.Sprintf("\n%s", strings.Join(msg, "\n")),
F: func() error {
return hp.updateRecords(dc.Name, create, del, mod)
},
},
}
return corrections, nil
}