mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-02-25 08:02:58 +08:00
LINODE: Adopt diff2 in compatibility mode (#1892)
This commit is contained in:
parent
1ab73aad37
commit
b6ee7161a5
2 changed files with 64 additions and 63 deletions
|
@ -14,5 +14,7 @@ func AuditRecords(records []*models.RecordConfig) []error {
|
||||||
|
|
||||||
a.Add("CAA", rejectif.CaaFlagIsNonZero) // Last verified 2022-03-25
|
a.Add("CAA", rejectif.CaaFlagIsNonZero) // Last verified 2022-03-25
|
||||||
|
|
||||||
|
a.Add("CAA", rejectif.CaaTargetContainsWhitespace) // Last verified 2023-01-15
|
||||||
|
|
||||||
return a.Audit(records)
|
return a.Audit(records)
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,76 +157,75 @@ func (api *linodeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod
|
||||||
}
|
}
|
||||||
|
|
||||||
var corrections []*models.Correction
|
var corrections []*models.Correction
|
||||||
if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives
|
var create, del, modify diff.Changeset
|
||||||
|
if !diff2.EnableDiff2 {
|
||||||
differ := diff.New(dc)
|
differ := diff.New(dc)
|
||||||
_, create, del, modify, err := differ.IncrementalDiff(existingRecords)
|
_, create, del, modify, err = differ.IncrementalDiff(existingRecords)
|
||||||
|
} else {
|
||||||
|
differ := diff.NewCompat(dc)
|
||||||
|
_, create, del, modify, err = differ.IncrementalDiff(existingRecords)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deletes first so changing type works etc.
|
||||||
|
for _, m := range del {
|
||||||
|
id := m.Existing.Original.(*domainRecord).ID
|
||||||
|
if id == 0 { // Skip ID 0, these are the default nameservers always present
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
corr := &models.Correction{
|
||||||
|
Msg: fmt.Sprintf("%s, Linode ID: %d", m.String(), id),
|
||||||
|
F: func() error {
|
||||||
|
return api.deleteRecord(domainID, id)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
corrections = append(corrections, corr)
|
||||||
|
}
|
||||||
|
for _, m := range create {
|
||||||
|
req, err := toReq(dc, m.Desired)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
j, err := json.Marshal(req)
|
||||||
// Deletes first so changing type works etc.
|
if err != nil {
|
||||||
for _, m := range del {
|
return nil, err
|
||||||
id := m.Existing.Original.(*domainRecord).ID
|
|
||||||
if id == 0 { // Skip ID 0, these are the default nameservers always present
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
corr := &models.Correction{
|
|
||||||
Msg: fmt.Sprintf("%s, Linode ID: %d", m.String(), id),
|
|
||||||
F: func() error {
|
|
||||||
return api.deleteRecord(domainID, id)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
corrections = append(corrections, corr)
|
|
||||||
}
|
}
|
||||||
for _, m := range create {
|
corr := &models.Correction{
|
||||||
req, err := toReq(dc, m.Desired)
|
Msg: fmt.Sprintf("%s: %s", m.String(), string(j)),
|
||||||
if err != nil {
|
F: func() error {
|
||||||
return nil, err
|
record, err := api.createRecord(domainID, req)
|
||||||
}
|
if err != nil {
|
||||||
j, err := json.Marshal(req)
|
return err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
// TTL isn't saved when creating a record, so we will need to modify it immediately afterwards
|
||||||
}
|
return api.modifyRecord(domainID, record.ID, req)
|
||||||
corr := &models.Correction{
|
},
|
||||||
Msg: fmt.Sprintf("%s: %s", m.String(), string(j)),
|
|
||||||
F: func() error {
|
|
||||||
record, err := api.createRecord(domainID, req)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// TTL isn't saved when creating a record, so we will need to modify it immediately afterwards
|
|
||||||
return api.modifyRecord(domainID, record.ID, req)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
corrections = append(corrections, corr)
|
|
||||||
}
|
}
|
||||||
for _, m := range modify {
|
corrections = append(corrections, corr)
|
||||||
id := m.Existing.Original.(*domainRecord).ID
|
}
|
||||||
if id == 0 { // Skip ID 0, these are the default nameservers always present
|
for _, m := range modify {
|
||||||
continue
|
id := m.Existing.Original.(*domainRecord).ID
|
||||||
}
|
if id == 0 { // Skip ID 0, these are the default nameservers always present
|
||||||
req, err := toReq(dc, m.Desired)
|
continue
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
req, err := toReq(dc, m.Desired)
|
||||||
}
|
if err != nil {
|
||||||
j, err := json.Marshal(req)
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
j, err := json.Marshal(req)
|
||||||
}
|
if err != nil {
|
||||||
corr := &models.Correction{
|
return nil, err
|
||||||
Msg: fmt.Sprintf("%s, Linode ID: %d: %s", m.String(), id, string(j)),
|
}
|
||||||
F: func() error {
|
corr := &models.Correction{
|
||||||
return api.modifyRecord(domainID, id, req)
|
Msg: fmt.Sprintf("%s, Linode ID: %d: %s", m.String(), id, string(j)),
|
||||||
},
|
F: func() error {
|
||||||
}
|
return api.modifyRecord(domainID, id, req)
|
||||||
corrections = append(corrections, corr)
|
},
|
||||||
}
|
}
|
||||||
|
corrections = append(corrections, corr)
|
||||||
return corrections, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert Future diff2 version here.
|
|
||||||
|
|
||||||
return corrections, nil
|
return corrections, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue