mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
CLOUDFLAREAPI: Fix TXT quoting bug (#1543)
* Cleanup * wip! * Fix cloudflare quote bug * wip! * cleanup * go generate
This commit is contained in:
@@ -2,10 +2,24 @@ package cloudflare
|
||||
|
||||
import (
|
||||
"github.com/StackExchange/dnscontrol/v3/models"
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/recordaudit"
|
||||
)
|
||||
|
||||
// AuditRecords returns an error if any records are not
|
||||
// supportable by this provider.
|
||||
func AuditRecords(records []*models.RecordConfig) error {
|
||||
|
||||
if err := recordaudit.TxtNoMultipleStrings(records); err != nil {
|
||||
return err
|
||||
} // Still needed as of 2022-06-18
|
||||
|
||||
if err := recordaudit.TxtNoTrailingSpace(records); err != nil {
|
||||
return err
|
||||
} // Still needed as of 2022-06-18
|
||||
|
||||
if err := recordaudit.TxtNotEmpty(records); err != nil {
|
||||
return err
|
||||
} // Still needed as of 2022-06-18
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -214,6 +214,14 @@ func (c *cloudflareProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
|
||||
|
||||
// Normalize
|
||||
models.PostProcessRecords(records)
|
||||
//txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records
|
||||
// Don't split.
|
||||
// Cloudflare's API only supports one TXT string of any non-zero length. No
|
||||
// multiple strings (TXTMulti).
|
||||
// When serving the DNS record, it splits strings >255 octets into
|
||||
// individual segments of 255 each. However that is hidden from the API.
|
||||
// Therefore, whether the string is 1 octet or thousands, just store it as
|
||||
// one string in the first element of .TxtStrings.
|
||||
|
||||
differ := diff.New(dc, getProxyMetadata)
|
||||
_, create, del, mod, err := differ.IncrementalDiff(records)
|
||||
@@ -636,6 +644,7 @@ func stringDefault(value interface{}, def string) string {
|
||||
}
|
||||
|
||||
func (c *cloudflareProvider) nativeToRecord(domain string, cr cloudflare.DNSRecord) (*models.RecordConfig, error) {
|
||||
|
||||
// normalize cname,mx,ns records with dots to be consistent with our config format.
|
||||
if cr.Type == "CNAME" || cr.Type == "MX" || cr.Type == "NS" || cr.Type == "PTR" {
|
||||
if cr.Content != "." {
|
||||
@@ -670,7 +679,10 @@ func (c *cloudflareProvider) nativeToRecord(domain string, cr cloudflare.DNSReco
|
||||
target); err != nil {
|
||||
return nil, fmt.Errorf("unparsable SRV record received from cloudflare: %w", err)
|
||||
}
|
||||
default: // "A", "AAAA", "ANAME", "CAA", "CNAME", "NS", "PTR", "TXT"
|
||||
case "TXT":
|
||||
err := rc.SetTargetTXT(cr.Content)
|
||||
return rc, err
|
||||
default:
|
||||
if err := rc.PopulateFromString(rType, cr.Content, domain); err != nil {
|
||||
return nil, fmt.Errorf("unparsable record received from cloudflare: %w", err)
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ func (c *cloudflareProvider) getRecordsForDomain(id string, domain string) ([]*m
|
||||
// create a correction to delete a record
|
||||
func (c *cloudflareProvider) deleteRec(rec cloudflare.DNSRecord, domainID string) *models.Correction {
|
||||
return &models.Correction{
|
||||
Msg: fmt.Sprintf("DELETE record: %s %s %d %s (id=%s)", rec.Name, rec.Type, rec.TTL, rec.Content, rec.ID),
|
||||
Msg: fmt.Sprintf("DELETE record: %s %s %d %q (id=%s)", rec.Name, rec.Type, rec.TTL, rec.Content, rec.ID),
|
||||
F: func() error {
|
||||
err := c.cfClient.DeleteDNSRecord(context.Background(), domainID, rec.ID)
|
||||
return err
|
||||
@@ -119,7 +119,7 @@ func (c *cloudflareProvider) createRec(rec *models.RecordConfig, domainID string
|
||||
prio = fmt.Sprintf(" %d ", rec.MxPreference)
|
||||
}
|
||||
if rec.Type == "TXT" {
|
||||
content = rec.GetTargetRFC1035Quoted()
|
||||
content = rec.GetTargetTXTJoined()
|
||||
}
|
||||
if rec.Type == "DS" {
|
||||
content = fmt.Sprintf("%d %d %d %s", rec.DsKeyTag, rec.DsAlgorithm, rec.DsDigestType, rec.DsDigest)
|
||||
@@ -183,7 +183,7 @@ func (c *cloudflareProvider) modifyRecord(domainID, recID string, proxied bool,
|
||||
TTL: int(rec.TTL),
|
||||
}
|
||||
if rec.Type == "TXT" {
|
||||
r.Content = rec.GetTargetRFC1035Quoted()
|
||||
r.Content = rec.GetTargetTXTJoined()
|
||||
}
|
||||
if rec.Type == "SRV" {
|
||||
r.Data = cfSrvData(rec)
|
||||
|
Reference in New Issue
Block a user