mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
REFACTOR: Opinion: TXT records are one long string (#2631)
Co-authored-by: Costas Drogos <costas.drogos@gmail.com> Co-authored-by: imlonghao <git@imlonghao.com> Co-authored-by: Jeffrey Cafferata <jeffrey@jcid.nl> Co-authored-by: Vincent Hagen <blackshadev@users.noreply.github.com>
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v4/models"
|
||||
"github.com/StackExchange/dnscontrol/v4/pkg/diff2"
|
||||
"github.com/StackExchange/dnscontrol/v4/pkg/txtutil"
|
||||
"github.com/StackExchange/dnscontrol/v4/providers"
|
||||
"github.com/transip/gotransip/v6"
|
||||
"github.com/transip/gotransip/v6/domain"
|
||||
@ -299,6 +300,7 @@ func (n *transipProvider) GetNameservers(domainName string) ([]*models.Nameserve
|
||||
return models.ToNameservers(nss)
|
||||
}
|
||||
|
||||
// recordToNative convrts RecordConfig TO Native.
|
||||
func recordToNative(config *models.RecordConfig, useOriginal bool) (domain.DNSEntry, error) {
|
||||
if useOriginal && config.Original != nil {
|
||||
return config.Original.(domain.DNSEntry), nil
|
||||
@ -308,10 +310,11 @@ func recordToNative(config *models.RecordConfig, useOriginal bool) (domain.DNSEn
|
||||
Name: config.Name,
|
||||
Expire: int(config.TTL),
|
||||
Type: config.Type,
|
||||
Content: getTargetRecordContent(config),
|
||||
Content: config.GetTargetCombinedFunc(txtutil.EncodeQuoted),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// nativeToRecord converts native to RecordConfig.
|
||||
func nativeToRecord(entry domain.DNSEntry, origin string) (*models.RecordConfig, error) {
|
||||
rc := &models.RecordConfig{
|
||||
TTL: uint32(entry.Expire),
|
||||
@ -319,7 +322,7 @@ func nativeToRecord(entry domain.DNSEntry, origin string) (*models.RecordConfig,
|
||||
Original: entry,
|
||||
}
|
||||
rc.SetLabel(entry.Name, origin)
|
||||
if err := rc.PopulateFromString(entry.Type, entry.Content, origin); err != nil {
|
||||
if err := rc.PopulateFromStringFunc(entry.Type, entry.Content, origin, txtutil.ParseQuoted); err != nil {
|
||||
return nil, fmt.Errorf("unparsable record received from TransIP: %w", err)
|
||||
}
|
||||
|
||||
@ -338,18 +341,3 @@ func removeOtherNS(dc *models.DomainConfig) {
|
||||
}
|
||||
dc.Records = newList
|
||||
}
|
||||
|
||||
func getTargetRecordContent(rc *models.RecordConfig) string {
|
||||
switch rtype := rc.Type; rtype {
|
||||
case "SSHFP":
|
||||
return fmt.Sprintf("%d %d %s", rc.SshfpAlgorithm, rc.SshfpFingerprint, rc.GetTargetField())
|
||||
case "DS":
|
||||
return fmt.Sprintf("%d %d %d %s", rc.DsKeyTag, rc.DsAlgorithm, rc.DsDigestType, rc.DsDigest)
|
||||
case "SRV":
|
||||
return fmt.Sprintf("%d %d %d %s", rc.SrvPriority, rc.SrvWeight, rc.SrvPort, rc.GetTargetField())
|
||||
case "TXT":
|
||||
return removeSlashes(models.StripQuotes(rc.GetTargetCombined()))
|
||||
default:
|
||||
return models.StripQuotes(rc.GetTargetCombined())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user