mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-11-10 17:26:10 +08:00
NAMEDOTCOM: Better estimate TXT length restrictions (#1627)
This commit is contained in:
parent
44001dc999
commit
c7d3667d87
1 changed files with 15 additions and 2 deletions
|
@ -2,6 +2,8 @@ package namedotcom
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/v3/models"
|
"github.com/StackExchange/dnscontrol/v3/models"
|
||||||
"github.com/StackExchange/dnscontrol/v3/pkg/recordaudit"
|
"github.com/StackExchange/dnscontrol/v3/pkg/recordaudit"
|
||||||
)
|
)
|
||||||
|
@ -24,13 +26,24 @@ func AuditRecords(records []*models.RecordConfig) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxLengthNDC returns and error if the sum of the strings
|
// MaxLengthNDC returns and error if the sum of the strings
|
||||||
// are longer than permitted by DigitalOcean. Sadly their
|
// are longer than permitted by NDC. Sadly their
|
||||||
// length limit is undocumented. This seems to work.
|
// length limit is undocumented. This seems to work.
|
||||||
func MaxLengthNDC(records []*models.RecordConfig) error {
|
func MaxLengthNDC(records []*models.RecordConfig) error {
|
||||||
for _, rc := range records {
|
for _, rc := range records {
|
||||||
|
|
||||||
if rc.HasFormatIdenticalToTXT() { // TXT and similar:
|
if rc.HasFormatIdenticalToTXT() { // TXT and similar:
|
||||||
if len(rc.GetTargetField()) > 512 {
|
// Sum the length of the segments:
|
||||||
|
sum := 0
|
||||||
|
for _, segment := range rc.TxtStrings {
|
||||||
|
sum += len(segment) // The length of each segment
|
||||||
|
sum += strings.Count(segment, `"`) // Add 1 for any char to be escaped
|
||||||
|
}
|
||||||
|
// Add the overhead of quoting them:
|
||||||
|
n := len(rc.TxtStrings)
|
||||||
|
if n > 0 {
|
||||||
|
sum += 2 + 3*(n-1) // Start and end double-quotes, plus `" "` between each segment.
|
||||||
|
}
|
||||||
|
if sum > 512 {
|
||||||
return fmt.Errorf("encoded txt too long")
|
return fmt.Errorf("encoded txt too long")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue