plugin/etcd: small refactor (#1749)

* plugin/etcd: small refactor

I think this function can be smaller.

* and make it compile
This commit is contained in:
Miek Gieben 2018-04-28 10:03:35 +01:00 committed by GitHub
parent 82d3195f2f
commit c0590e4ec4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,7 +14,7 @@ import (
// A returns A records from Backend or an error.
func A(b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, err error) {
services, err := checkZoneForRecord(b, zone, state, opt)
services, err := checkForApex(b, zone, state, opt)
if err != nil {
return nil, err
}
@ -78,7 +78,7 @@ func A(b ServiceBackend, zone string, state request.Request, previousRecords []d
// AAAA returns AAAA records from Backend or an error.
func AAAA(b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, err error) {
services, err := checkZoneForRecord(b, zone, state, opt)
services, err := checkForApex(b, zone, state, opt)
if err != nil {
return nil, err
}
@ -403,37 +403,26 @@ func newAddress(s msg.Service, name string, ip net.IP, what uint16) dns.RR {
return &dns.AAAA{Hdr: hdr, AAAA: ip}
}
func checkZoneForRecord(b ServiceBackend, zone string, state request.Request, opt Options) ([]msg.Service, error) {
var services []msg.Service
var err error
// if the zone name itself is queried we fake the query to search for a special entry
// this is equivalent to the NS search code
if state.Name() == zone {
// checkForApex checks the spcecial apex.dns directory for records that will be returned as A or AAAA.
func checkForApex(b ServiceBackend, zone string, state request.Request, opt Options) ([]msg.Service, error) {
if state.Name() != zone {
return b.Services(state, false, opt)
}
// If the zone name itself is queried we fake the query to search for a special entry
// this is equivalent to the NS search code.
old := state.QName()
state.Clear()
state.Req.Question[0].Name = dnsutil.Join([]string{"apex.dns", zone})
services, err = b.Services(state, false, opt)
if err != nil {
// it might be possible, that "apex.dns.zone" does not exists
// we set back the query and try it once again to restore the backward compatibility behavior
services, err := b.Services(state, false, opt)
if err == nil {
state.Req.Question[0].Name = old
services, err = b.Services(state, false, opt)
// if it still errors, we return the error
if err != nil {
return services, err
}
}
state.Req.Question[0].Name = old
} else {
services, err = b.Services(state, false, opt)
if err != nil {
return services, err
}
}
return services, err
return b.Services(state, false, opt)
}
const hostmaster = "hostmaster"