mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	* Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * More lint fixes This leaves: ~~~ middleware/kubernetes/nametemplate/nametemplate.go:64:6: exported type NameTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:71:1: exported method NameTemplate.SetTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:108:1: exported method NameTemplate.GetZoneFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:116:1: exported method NameTemplate.GetNamespaceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:120:1: exported method NameTemplate.GetServiceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:124:1: exported method NameTemplate.GetTypeFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:135:1: exported method NameTemplate.GetSymbolFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:167:1: exported method NameTemplate.IsValid should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:182:6: exported type NameValues should have comment or be unexported middleware/kubernetes/util/util.go:1:1: package comment should be of the form "Package util ..." middleware/kubernetes/util/util.go:27:2: exported const WildcardStar should have comment (or a comment on this block) or be unexported middleware/proxy/lookup.go:66:1: exported method Proxy.Forward should have comment or be unexported middleware/proxy/proxy.go:24:6: exported type Client should have comment or be unexported middleware/proxy/proxy.go:107:1: exported function Clients should have comment or be unexported middleware/proxy/reverseproxy.go:10:6: exported type ReverseProxy should have comment or be unexported middleware/proxy/reverseproxy.go:16:1: exported method ReverseProxy.ServeDNS should have comment or be unexported middleware/proxy/upstream.go:42:6: exported type Options should have comment or be unexported ~~~ I plan on reworking the proxy anyway, so I'll leave that be.
		
			
				
	
	
		
			138 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			138 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package etcd
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 
 | |
| 	"github.com/miekg/coredns/middleware"
 | |
| 	"github.com/miekg/coredns/middleware/etcd/msg"
 | |
| 	"github.com/miekg/coredns/middleware/pkg/dnsutil"
 | |
| 	"github.com/miekg/coredns/request"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| 	"golang.org/x/net/context"
 | |
| )
 | |
| 
 | |
| // ServeDNS implements the middleware.Handler interface.
 | |
| func (e *Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
 | |
| 	opt := Options{}
 | |
| 	state := request.Request{W: w, Req: r}
 | |
| 	if state.QClass() != dns.ClassINET {
 | |
| 		return dns.RcodeServerFailure, fmt.Errorf("can only deal with ClassINET")
 | |
| 	}
 | |
| 	name := state.Name()
 | |
| 	if e.Debug {
 | |
| 		if debug := isDebug(name); debug != "" {
 | |
| 			opt.Debug = r.Question[0].Name
 | |
| 			state.Clear()
 | |
| 			state.Req.Question[0].Name = debug
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	// We need to check stubzones first, because we may get a request for a zone we
 | |
| 	// are not auth. for *but* do have a stubzone forward for. If we do the stubzone
 | |
| 	// handler will handle the request.
 | |
| 	if e.Stubmap != nil && len(*e.Stubmap) > 0 {
 | |
| 		for zone := range *e.Stubmap {
 | |
| 			if middleware.Name(zone).Matches(name) {
 | |
| 				stub := Stub{Etcd: e, Zone: zone}
 | |
| 				return stub.ServeDNS(ctx, w, r)
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	zone := middleware.Zones(e.Zones).Matches(state.Name())
 | |
| 	if zone == "" {
 | |
| 		if e.Next == nil {
 | |
| 			return dns.RcodeServerFailure, nil
 | |
| 		}
 | |
| 		if opt.Debug != "" {
 | |
| 			r.Question[0].Name = opt.Debug
 | |
| 		}
 | |
| 		return e.Next.ServeDNS(ctx, w, r)
 | |
| 	}
 | |
| 
 | |
| 	var (
 | |
| 		records, extra []dns.RR
 | |
| 		debug          []msg.Service
 | |
| 		err            error
 | |
| 	)
 | |
| 	switch state.Type() {
 | |
| 	case "A":
 | |
| 		records, debug, err = e.A(zone, state, nil, opt)
 | |
| 	case "AAAA":
 | |
| 		records, debug, err = e.AAAA(zone, state, nil, opt)
 | |
| 	case "TXT":
 | |
| 		records, debug, err = e.TXT(zone, state, opt)
 | |
| 	case "CNAME":
 | |
| 		records, debug, err = e.CNAME(zone, state, opt)
 | |
| 	case "PTR":
 | |
| 		records, debug, err = e.PTR(zone, state, opt)
 | |
| 	case "MX":
 | |
| 		records, extra, debug, err = e.MX(zone, state, opt)
 | |
| 	case "SRV":
 | |
| 		records, extra, debug, err = e.SRV(zone, state, opt)
 | |
| 	case "SOA":
 | |
| 		records, debug, err = e.SOA(zone, state, opt)
 | |
| 	case "NS":
 | |
| 		if state.Name() == zone {
 | |
| 			records, extra, debug, err = e.NS(zone, state, opt)
 | |
| 			break
 | |
| 		}
 | |
| 		fallthrough
 | |
| 	default:
 | |
| 		// Do a fake A lookup, so we can distinguish between NODATA and NXDOMAIN
 | |
| 		_, debug, err = e.A(zone, state, nil, opt)
 | |
| 	}
 | |
| 
 | |
| 	if opt.Debug != "" {
 | |
| 		// Substitute this name with the original when we return the request.
 | |
| 		state.Clear()
 | |
| 		state.Req.Question[0].Name = opt.Debug
 | |
| 	}
 | |
| 
 | |
| 	if isEtcdNameError(err) {
 | |
| 		return e.Err(zone, dns.RcodeNameError, state, debug, err, opt)
 | |
| 	}
 | |
| 	if err != nil {
 | |
| 		return e.Err(zone, dns.RcodeServerFailure, state, debug, err, opt)
 | |
| 	}
 | |
| 
 | |
| 	if len(records) == 0 {
 | |
| 		return e.Err(zone, dns.RcodeSuccess, state, debug, err, opt)
 | |
| 	}
 | |
| 
 | |
| 	m := new(dns.Msg)
 | |
| 	m.SetReply(r)
 | |
| 	m.Authoritative, m.RecursionAvailable, m.Compress = true, true, true
 | |
| 	m.Answer = append(m.Answer, records...)
 | |
| 	m.Extra = append(m.Extra, extra...)
 | |
| 	if opt.Debug != "" {
 | |
| 		m.Extra = append(m.Extra, servicesToTxt(debug)...)
 | |
| 	}
 | |
| 
 | |
| 	m = dnsutil.Dedup(m)
 | |
| 	state.SizeAndDo(m)
 | |
| 	m, _ = state.Scrub(m)
 | |
| 	w.WriteMsg(m)
 | |
| 	return dns.RcodeSuccess, nil
 | |
| }
 | |
| 
 | |
| // Err write an error response to the client.
 | |
| func (e *Etcd) Err(zone string, rcode int, state request.Request, debug []msg.Service, err error, opt Options) (int, error) {
 | |
| 	m := new(dns.Msg)
 | |
| 	m.SetRcode(state.Req, rcode)
 | |
| 	m.Authoritative, m.RecursionAvailable, m.Compress = true, true, true
 | |
| 	m.Ns, _, _ = e.SOA(zone, state, opt)
 | |
| 	if opt.Debug != "" {
 | |
| 		m.Extra = servicesToTxt(debug)
 | |
| 		txt := errorToTxt(err)
 | |
| 		if txt != nil {
 | |
| 			m.Extra = append(m.Extra, errorToTxt(err))
 | |
| 		}
 | |
| 	}
 | |
| 	state.SizeAndDo(m)
 | |
| 	state.W.WriteMsg(m)
 | |
| 	// Return success as the rcode to signal we have written to the client.
 | |
| 	return dns.RcodeSuccess, nil
 | |
| }
 |