Make the receiver a pointer so that the uptdateStubZones map update will retain the stubzones found, unlike the current case where the update will be applied and then promptly forgotten, because it is working on a copy. Add test/etcd_test.go to test a large part of the code. This didn't catch the chaos middleware hack though. The chaos middleware zones are now *not* automatically added. You have to take care of that by yourself (docs updates). When using debug queries and falling through to the next middleware in etcd, restore the original (with o-o.debug) query before passing it on.
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package etcd
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/miekg/coredns/middleware/etcd/msg"
|
|
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
const debugName = "o-o.debug."
|
|
|
|
// isDebug checks if name is a debugging name, i.e. starts with o-o.debug.
|
|
// it return the empty string if it is not a debug message, otherwise it will return the
|
|
// name with o-o.debug. stripped off. Must be called with name lowercased.
|
|
func isDebug(name string) string {
|
|
if len(name) == len(debugName) {
|
|
return ""
|
|
}
|
|
name = strings.ToLower(name)
|
|
debug := strings.HasPrefix(name, debugName)
|
|
if !debug {
|
|
return ""
|
|
}
|
|
return name[len(debugName):]
|
|
}
|
|
|
|
// servicesToTxt puts debug in TXT RRs.
|
|
func servicesToTxt(debug []msg.Service) []dns.RR {
|
|
if debug == nil {
|
|
return nil
|
|
}
|
|
|
|
rr := make([]dns.RR, len(debug))
|
|
for i, d := range debug {
|
|
rr[i] = d.RR()
|
|
}
|
|
return rr
|
|
}
|
|
|
|
func errorToTxt(err error) dns.RR {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
msg := err.Error()
|
|
if len(msg) > 255 {
|
|
msg = msg[:255]
|
|
}
|
|
t := new(dns.TXT)
|
|
t.Hdr.Class = dns.ClassCHAOS
|
|
t.Hdr.Ttl = 0
|
|
t.Hdr.Rrtype = dns.TypeTXT
|
|
t.Hdr.Name = "."
|
|
|
|
t.Txt = []string{msg}
|
|
return t
|
|
}
|