From 096458d91ccdbf5a09763f9e589c6be99ed19216 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Sun, 29 Nov 2020 14:39:15 -0500 Subject: [PATCH] CLOUDFLAREAPI: Support TXTMulti and empty TXT targets (#978) * CLOUDFLAREAPI: Add TXTMulti support * CLOUDFLAREAPI: Support TXTMulti and empty TXT strings --- integrationTest/integration_test.go | 2 +- providers/cloudflare/cloudflareProvider.go | 1 + providers/cloudflare/rest.go | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/integrationTest/integration_test.go b/integrationTest/integration_test.go index 03b3e9c42..d4fe1fe52 100644 --- a/integrationTest/integration_test.go +++ b/integrationTest/integration_test.go @@ -698,7 +698,7 @@ func makeTests(t *testing.T) []*TestGroup { ), testgroup("empty TXT", - not("CLOUDFLAREAPI", "HETZNER", "HEXONET", "INWX", "NETCUP"), + not("HETZNER", "HEXONET", "INWX", "NETCUP"), tc("TXT with empty str", txt("foo1", "")), // https://github.com/StackExchange/dnscontrol/issues/598 // We decided that permitting the TXT target to be an empty diff --git a/providers/cloudflare/cloudflareProvider.go b/providers/cloudflare/cloudflareProvider.go index b3b7e7f7a..17907b77d 100644 --- a/providers/cloudflare/cloudflareProvider.go +++ b/providers/cloudflare/cloudflareProvider.go @@ -45,6 +45,7 @@ var features = providers.DocumentationNotes{ providers.CanUseTLSA: providers.Can(), providers.CanUseSSHFP: providers.Can(), providers.CanUseDS: providers.Can(), + providers.CanUseTXTMulti: providers.Can(), providers.DocCreateDomains: providers.Can(), providers.DocDualHost: providers.Cannot("Cloudflare will not work well in situations where it is not the only DNS server"), providers.DocOfficiallySupported: providers.Can(), diff --git a/providers/cloudflare/rest.go b/providers/cloudflare/rest.go index 441d00f96..2757df01b 100644 --- a/providers/cloudflare/rest.go +++ b/providers/cloudflare/rest.go @@ -194,6 +194,11 @@ func (c *cloudflareProvider) createRec(rec *models.RecordConfig, domainID string if rec.Type == "MX" { prio = fmt.Sprintf(" %d ", rec.MxPreference) } + if rec.Type == "TXT" { + if len(rec.TxtStrings) > 1 { + content = `"` + strings.Join(rec.TxtStrings, `" "`) + `"` + } + } if rec.Type == "DS" { content = fmt.Sprintf("%d %d %d %s", rec.DsKeyTag, rec.DsAlgorithm, rec.DsDigestType, rec.DsDigest) } @@ -272,6 +277,11 @@ func (c *cloudflareProvider) modifyRecord(domainID, recID string, proxied bool, TTL: rec.TTL, Data: nil, } + if rec.Type == "TXT" { + if len(rec.TxtStrings) > 1 { + r.Content = `"` + strings.Join(rec.TxtStrings, `" "`) + `"` + } + } if rec.Type == "SRV" { r.Data = cfSrvData(rec) r.Name = rec.GetLabelFQDN()