mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-11 18:08:57 +08:00
ccb582b278
* Remove deprecated io/ioutil * fixup! * staticcheck and linting * revert models/provider.go * Fix imports to new style * linting
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package rwth
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/StackExchange/dnscontrol/v3/models"
|
|
"github.com/StackExchange/dnscontrol/v3/pkg/prettyzone"
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
// Print the generateZoneFileHelper
|
|
func (api *rwthProvider) printRecConfig(rr models.RecordConfig) string {
|
|
// Similar to prettyzone
|
|
// Fake types are commented out.
|
|
prefix := ""
|
|
_, ok := dns.StringToType[rr.Type]
|
|
if !ok {
|
|
prefix = ";"
|
|
}
|
|
|
|
// ttl
|
|
ttl := ""
|
|
if rr.TTL != 172800 && rr.TTL != 0 {
|
|
ttl = fmt.Sprint(rr.TTL)
|
|
}
|
|
|
|
// type
|
|
typeStr := rr.Type
|
|
|
|
// the remaining line
|
|
target := rr.GetTargetCombined()
|
|
|
|
// comment
|
|
comment := ";"
|
|
|
|
return fmt.Sprintf("%s%s%s\n",
|
|
prefix, prettyzone.FormatLine([]int{10, 5, 2, 5, 0}, []string{rr.NameFQDN, ttl, "IN", typeStr, target}), comment)
|
|
}
|
|
|
|
// NewRR returns custom dns.NewRR with RWTH default TTL
|
|
func NewRR(s string) (dns.RR, error) {
|
|
if len(s) > 0 && s[len(s)-1] != '\n' { // We need a closing newline
|
|
return ReadRR(strings.NewReader(s + "\n"))
|
|
}
|
|
return ReadRR(strings.NewReader(s))
|
|
}
|
|
|
|
// ReadRR reads an RR from r.
|
|
func ReadRR(r io.Reader) (dns.RR, error) {
|
|
zp := dns.NewZoneParser(r, ".", "")
|
|
zp.SetDefaultTTL(172800)
|
|
zp.SetIncludeAllowed(true)
|
|
rr, _ := zp.Next()
|
|
return rr, zp.Err()
|
|
}
|