1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Improve MSDNS naptr support (#1165)

* MSDNS: Improve reliability of zone dump

* Update tests

* MSDNS: Add initial NAPTR support

* Update

* fix tests

* fix tests

* Fixing integration tests for NAPTR

* Handle bad JSON. Handle NAPTR TTLs
This commit is contained in:
Tom Limoncelli
2021-06-24 18:26:21 -04:00
committed by GitHub
parent 6d64fc8cac
commit 654736be29
15 changed files with 305 additions and 36 deletions

View File

@ -1,6 +1,7 @@
package commands
import (
"encoding/json"
"fmt"
"os"
"strings"
@ -249,6 +250,16 @@ func GetZone(args GetZoneArgs) error {
return nil
}
// jsonQuoted returns a properly escaped JSON string (without quotes).
func jsonQuoted(i string) string {
// https://stackoverflow.com/questions/51691901
b, err := json.Marshal(i)
if err != nil {
panic(err)
}
return string(b)
}
func formatDsl(zonename string, rec *models.RecordConfig, defaultTTL uint32) string {
target := rec.GetTargetCombined()
@ -272,6 +283,15 @@ func formatDsl(zonename string, rec *models.RecordConfig, defaultTTL uint32) str
return makeCaa(rec, ttlop)
case "MX":
target = fmt.Sprintf("%d, '%s'", rec.MxPreference, rec.GetTargetField())
case "NAPTR":
target = fmt.Sprintf(`%d, %d, %s, %s, %s, %s`,
rec.NaptrOrder, // 1
rec.NaptrPreference, // 10
jsonQuoted(rec.NaptrFlags), // U
jsonQuoted(rec.NaptrService), // E2U+sip
jsonQuoted(rec.NaptrRegexp), // regex
jsonQuoted(rec.GetTargetField()), // .
)
case "SSHFP":
target = fmt.Sprintf("%d, %d, '%s'", rec.SshfpAlgorithm, rec.SshfpFingerprint, rec.GetTargetField())
case "SOA":