From b6ee7161a5041c5ae9fc467ea7f77329c673851d Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Wed, 18 Jan 2023 08:42:22 -0500 Subject: [PATCH] LINODE: Adopt diff2 in compatibility mode (#1892) --- providers/linode/auditrecords.go | 2 + providers/linode/linodeProvider.go | 125 ++++++++++++++--------------- 2 files changed, 64 insertions(+), 63 deletions(-) diff --git a/providers/linode/auditrecords.go b/providers/linode/auditrecords.go index 312423971..874145075 100644 --- a/providers/linode/auditrecords.go +++ b/providers/linode/auditrecords.go @@ -14,5 +14,7 @@ func AuditRecords(records []*models.RecordConfig) []error { a.Add("CAA", rejectif.CaaFlagIsNonZero) // Last verified 2022-03-25 + a.Add("CAA", rejectif.CaaTargetContainsWhitespace) // Last verified 2023-01-15 + return a.Audit(records) } diff --git a/providers/linode/linodeProvider.go b/providers/linode/linodeProvider.go index b35463674..3f4239ea6 100644 --- a/providers/linode/linodeProvider.go +++ b/providers/linode/linodeProvider.go @@ -157,76 +157,75 @@ func (api *linodeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod } 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) - _, 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 { 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) + j, err := json.Marshal(req) + if err != nil { + return nil, err } - for _, m := range create { - req, err := toReq(dc, m.Desired) - if err != nil { - return nil, err - } - j, err := json.Marshal(req) - if err != nil { - return nil, err - } - 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) + 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) + }, } - for _, m := range modify { - id := m.Existing.Original.(*domainRecord).ID - if id == 0 { // Skip ID 0, these are the default nameservers always present - continue - } - req, err := toReq(dc, m.Desired) - if err != nil { - return nil, err - } - j, err := json.Marshal(req) - if err != nil { - return nil, err - } - corr := &models.Correction{ - 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) - } - - return corrections, nil + corrections = append(corrections, corr) + } + for _, m := range modify { + id := m.Existing.Original.(*domainRecord).ID + if id == 0 { // Skip ID 0, these are the default nameservers always present + continue + } + req, err := toReq(dc, m.Desired) + if err != nil { + return nil, err + } + j, err := json.Marshal(req) + if err != nil { + return nil, err + } + corr := &models.Correction{ + 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) } - - // Insert Future diff2 version here. return corrections, nil }