mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-09-06 13:14:25 +08:00
NAMEDOTCOM: add TXTMulti capability (#299)
* add TXTMulti capability to the namedotcom provider * run go generate * escape multi txt records before sending to the API
This commit is contained in:
parent
c4ec6c8246
commit
91e2cf67ef
4 changed files with 31 additions and 3 deletions
|
@ -365,7 +365,9 @@
|
|||
<td><i class="fa fa-minus dim"></i></td>
|
||||
<td><i class="fa fa-minus dim"></i></td>
|
||||
<td><i class="fa fa-minus dim"></i></td>
|
||||
<td><i class="fa fa-minus dim"></i></td>
|
||||
<td class="success">
|
||||
<i class="fa fa-check text-success" aria-hidden="true"></i>
|
||||
</td>
|
||||
<td><i class="fa fa-minus dim"></i></td>
|
||||
<td><i class="fa fa-minus dim"></i></td>
|
||||
<td class="success">
|
||||
|
|
|
@ -466,11 +466,17 @@ func makeTests(t *testing.T) []*TestCase {
|
|||
txtmulti("foo2", []string{"one", "two"}),
|
||||
txtmulti("foo3", []string{"eh", "bee", "cee"}),
|
||||
),
|
||||
tc("Create TXTMulti with quotes",
|
||||
txtmulti("foo1", []string{"simple"}),
|
||||
txtmulti("foo2", []string{"o\"ne", "tw\"o"}),
|
||||
txtmulti("foo3", []string{"eh", "bee", "cee"}),
|
||||
),
|
||||
tc("Change TXTMulti",
|
||||
txtmulti("foo1", []string{"dimple"}),
|
||||
txtmulti("foo2", []string{"fun", "two"}),
|
||||
txtmulti("foo3", []string{"eh", "bzz", "cee"}),
|
||||
),
|
||||
tc("Empty"),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ var features = providers.DocumentationNotes{
|
|||
providers.CanUseAlias: providers.Can(),
|
||||
providers.CanUsePTR: providers.Cannot("PTR records are not supported (See Link)", "https://www.name.com/support/articles/205188508-Reverse-DNS-records"),
|
||||
providers.CanUseSRV: providers.Can(),
|
||||
providers.CanUseTXTMulti: providers.Can(),
|
||||
providers.DocCreateDomains: providers.Cannot("New domains require registration"),
|
||||
providers.DocDualHost: providers.Cannot("Apex NS records not editable"),
|
||||
providers.DocOfficiallySupported: providers.Can(),
|
||||
|
|
|
@ -2,6 +2,7 @@ package namedotcom
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -82,6 +83,9 @@ func checkNSModifications(dc *models.DomainConfig) {
|
|||
dc.Records = newList
|
||||
}
|
||||
|
||||
// finds a string surrounded by quotes that might contain an escaped quote charactor.
|
||||
var quotedStringRegexp = regexp.MustCompile("\"((?:[^\"\\\\]|\\\\.)*)\"")
|
||||
|
||||
func toRecord(r *namecom.Record) *models.RecordConfig {
|
||||
rc := &models.RecordConfig{
|
||||
NameFQDN: r.Fqdn,
|
||||
|
@ -91,8 +95,16 @@ func toRecord(r *namecom.Record) *models.RecordConfig {
|
|||
Original: r,
|
||||
}
|
||||
switch r.Type { // #rtype_variations
|
||||
case "A", "AAAA", "ANAME", "CNAME", "NS", "TXT":
|
||||
case "A", "AAAA", "ANAME", "CNAME", "NS":
|
||||
// nothing additional.
|
||||
case "TXT":
|
||||
if r.Answer[0] == '"' && r.Answer[len(r.Answer)-1] == '"' {
|
||||
txtStrings := []string{}
|
||||
for _, t := range quotedStringRegexp.FindAllStringSubmatch(r.Answer, -1) {
|
||||
txtStrings = append(txtStrings, t[1])
|
||||
}
|
||||
rc.SetTxts(txtStrings)
|
||||
}
|
||||
case "MX":
|
||||
rc.MxPreference = uint16(r.Priority)
|
||||
case "SRV":
|
||||
|
@ -153,8 +165,15 @@ func (n *NameCom) createRecord(rc *models.RecordConfig, domain string) error {
|
|||
}
|
||||
|
||||
switch rc.Type { // #rtype_variations
|
||||
case "A", "AAAA", "ANAME", "CNAME", "MX", "NS", "TXT":
|
||||
case "A", "AAAA", "ANAME", "CNAME", "MX", "NS":
|
||||
// nothing
|
||||
case "TXT":
|
||||
if len(rc.TxtStrings) > 1 {
|
||||
record.Answer = ""
|
||||
for _, t := range rc.TxtStrings {
|
||||
record.Answer += "\"" + strings.Replace(t, "\"", "\\\"", -1) + "\""
|
||||
}
|
||||
}
|
||||
case "SRV":
|
||||
record.Answer = fmt.Sprintf("%d %d %v", rc.SrvWeight, rc.SrvPort, rc.Target)
|
||||
record.Priority = uint32(rc.SrvPriority)
|
||||
|
|
Loading…
Add table
Reference in a new issue