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:
Pat Moroney 2018-01-11 05:23:59 -07:00 committed by Tom Limoncelli
parent c4ec6c8246
commit 91e2cf67ef
4 changed files with 31 additions and 3 deletions

View file

@ -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><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><i class="fa fa-minus dim"></i></td> <td><i class="fa fa-minus dim"></i></td>
<td class="success"> <td class="success">

View file

@ -466,11 +466,17 @@ func makeTests(t *testing.T) []*TestCase {
txtmulti("foo2", []string{"one", "two"}), txtmulti("foo2", []string{"one", "two"}),
txtmulti("foo3", []string{"eh", "bee", "cee"}), 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", tc("Change TXTMulti",
txtmulti("foo1", []string{"dimple"}), txtmulti("foo1", []string{"dimple"}),
txtmulti("foo2", []string{"fun", "two"}), txtmulti("foo2", []string{"fun", "two"}),
txtmulti("foo3", []string{"eh", "bzz", "cee"}), txtmulti("foo3", []string{"eh", "bzz", "cee"}),
), ),
tc("Empty"),
) )
} }

View file

@ -22,6 +22,7 @@ var features = providers.DocumentationNotes{
providers.CanUseAlias: providers.Can(), 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.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.CanUseSRV: providers.Can(),
providers.CanUseTXTMulti: providers.Can(),
providers.DocCreateDomains: providers.Cannot("New domains require registration"), providers.DocCreateDomains: providers.Cannot("New domains require registration"),
providers.DocDualHost: providers.Cannot("Apex NS records not editable"), providers.DocDualHost: providers.Cannot("Apex NS records not editable"),
providers.DocOfficiallySupported: providers.Can(), providers.DocOfficiallySupported: providers.Can(),

View file

@ -2,6 +2,7 @@ package namedotcom
import ( import (
"fmt" "fmt"
"regexp"
"strconv" "strconv"
"strings" "strings"
@ -82,6 +83,9 @@ func checkNSModifications(dc *models.DomainConfig) {
dc.Records = newList 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 { func toRecord(r *namecom.Record) *models.RecordConfig {
rc := &models.RecordConfig{ rc := &models.RecordConfig{
NameFQDN: r.Fqdn, NameFQDN: r.Fqdn,
@ -91,8 +95,16 @@ func toRecord(r *namecom.Record) *models.RecordConfig {
Original: r, Original: r,
} }
switch r.Type { // #rtype_variations switch r.Type { // #rtype_variations
case "A", "AAAA", "ANAME", "CNAME", "NS", "TXT": case "A", "AAAA", "ANAME", "CNAME", "NS":
// nothing additional. // 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": case "MX":
rc.MxPreference = uint16(r.Priority) rc.MxPreference = uint16(r.Priority)
case "SRV": case "SRV":
@ -153,8 +165,15 @@ func (n *NameCom) createRecord(rc *models.RecordConfig, domain string) error {
} }
switch rc.Type { // #rtype_variations switch rc.Type { // #rtype_variations
case "A", "AAAA", "ANAME", "CNAME", "MX", "NS", "TXT": case "A", "AAAA", "ANAME", "CNAME", "MX", "NS":
// nothing // nothing
case "TXT":
if len(rc.TxtStrings) > 1 {
record.Answer = ""
for _, t := range rc.TxtStrings {
record.Answer += "\"" + strings.Replace(t, "\"", "\\\"", -1) + "\""
}
}
case "SRV": case "SRV":
record.Answer = fmt.Sprintf("%d %d %v", rc.SrvWeight, rc.SrvPort, rc.Target) record.Answer = fmt.Sprintf("%d %d %v", rc.SrvWeight, rc.SrvPort, rc.Target)
record.Priority = uint32(rc.SrvPriority) record.Priority = uint32(rc.SrvPriority)