plugin/template: small tweaks (#1366)
Small README updates, and fallthrough fixes (using less code)
This commit is contained in:
parent
0091e1c9dc
commit
a19ea63d3a
5 changed files with 46 additions and 51 deletions
|
@ -15,8 +15,8 @@ template CLASS TYPE [ZONE...] {
|
|||
[additional RR]
|
||||
[authority RR]
|
||||
[...]
|
||||
[rcode responsecode]
|
||||
[fallthrough [fallthrough zone...]]
|
||||
[rcode CODE]
|
||||
[fallthrough [ZONE...]]
|
||||
}
|
||||
~~~
|
||||
|
||||
|
@ -28,7 +28,8 @@ template CLASS TYPE [ZONE...] {
|
|||
build by a [Go template](https://golang.org/pkg/text/template/) that contains the reply.
|
||||
* `rcode` **CODE** A response code (`NXDOMAIN, SERVFAIL, ...`). The default is `SUCCESS`.
|
||||
* `fallthrough` Continue with the next plugin if the zone matched but no regex did not match.
|
||||
* `fallthrough zone` One or more zones that may fall through to other plugins. Defaults to all zones of the template.
|
||||
If specific zones are listed (for example `in-addr.arpa` and `ip6.arpa`), then only queries for
|
||||
those zones will be subject to fallthrough.
|
||||
|
||||
At least one `answer` or `rcode` directive is needed (e.g. `rcode NXDOMAIN`).
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"github.com/coredns/coredns/core/dnsserver"
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/metrics"
|
||||
"github.com/mholt/caddy"
|
||||
|
||||
"github.com/mholt/caddy"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
|
|
|
@ -140,12 +140,7 @@ func templateParse(c *caddy.Controller) (handler Handler, err error) {
|
|||
t.rcode = rcode
|
||||
|
||||
case "fallthrough":
|
||||
args := c.RemainingArgs()
|
||||
if len(args) > 0 {
|
||||
t.fthrough.SetZonesFromArgs(c.RemainingArgs())
|
||||
} else {
|
||||
t.fthrough.SetZonesFromArgs(zones)
|
||||
}
|
||||
t.fall.SetZonesFromArgs(c.RemainingArgs())
|
||||
|
||||
default:
|
||||
return handler, c.ArgErr()
|
||||
|
|
|
@ -31,7 +31,7 @@ type template struct {
|
|||
authority []*gotmpl.Template
|
||||
qclass uint16
|
||||
qtype uint16
|
||||
fthrough fall.F
|
||||
fall fall.F
|
||||
}
|
||||
|
||||
type templateData struct {
|
||||
|
@ -177,5 +177,5 @@ func (t template) match(state request.Request, zone string) (templateData, bool,
|
|||
return data, true, false
|
||||
}
|
||||
|
||||
return data, false, t.fthrough.Through(state.Name())
|
||||
return data, false, t.fall.Through(state.Name())
|
||||
}
|
||||
|
|
|
@ -5,14 +5,13 @@ import (
|
|||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/coredns/coredns/plugin/test"
|
||||
"github.com/mholt/caddy"
|
||||
|
||||
gotmpl "text/template"
|
||||
|
||||
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
||||
"github.com/coredns/coredns/plugin/pkg/fall"
|
||||
"github.com/coredns/coredns/plugin/test"
|
||||
|
||||
"github.com/mholt/caddy"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
|
@ -23,7 +22,7 @@ func TestHandler(t *testing.T) {
|
|||
answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }} 60 IN A 10.{{ .Group.b }}.{{ .Group.c }}.{{ .Group.d }}"))},
|
||||
qclass: dns.ClassANY,
|
||||
qtype: dns.TypeANY,
|
||||
fthrough: fall.F{Zones: []string{"."}},
|
||||
fall: fall.F{Zones: []string{"."}},
|
||||
zones: []string{"."},
|
||||
}
|
||||
exampleDomainANSTemplate := template{
|
||||
|
@ -33,7 +32,7 @@ func TestHandler(t *testing.T) {
|
|||
authority: []*gotmpl.Template{gotmpl.Must(gotmpl.New("authority").Parse("example. IN NS ns0.example.com."))},
|
||||
qclass: dns.ClassANY,
|
||||
qtype: dns.TypeANY,
|
||||
fthrough: fall.F{Zones: []string{"."}},
|
||||
fall: fall.F{Zones: []string{"."}},
|
||||
zones: []string{"."},
|
||||
}
|
||||
exampleDomainMXTemplate := template{
|
||||
|
@ -42,7 +41,7 @@ func TestHandler(t *testing.T) {
|
|||
additional: []*gotmpl.Template{gotmpl.Must(gotmpl.New("additional").Parse("{{ .Name }} 60 IN A 10.{{ .Group.b }}.{{ .Group.c }}.{{ .Group.d }}"))},
|
||||
qclass: dns.ClassANY,
|
||||
qtype: dns.TypeANY,
|
||||
fthrough: fall.F{Zones: []string{"."}},
|
||||
fall: fall.F{Zones: []string{"."}},
|
||||
zones: []string{"."},
|
||||
}
|
||||
invalidDomainTemplate := template{
|
||||
|
@ -51,7 +50,7 @@ func TestHandler(t *testing.T) {
|
|||
answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("invalid. 60 {{ .Class }} SOA a.invalid. b.invalid. (1 60 60 60 60)"))},
|
||||
qclass: dns.ClassANY,
|
||||
qtype: dns.TypeANY,
|
||||
fthrough: fall.F{Zones: []string{"."}},
|
||||
fall: fall.F{Zones: []string{"."}},
|
||||
zones: []string{"."},
|
||||
}
|
||||
rcodeServfailTemplate := template{
|
||||
|
@ -59,7 +58,7 @@ func TestHandler(t *testing.T) {
|
|||
rcode: dns.RcodeServerFailure,
|
||||
qclass: dns.ClassANY,
|
||||
qtype: dns.TypeANY,
|
||||
fthrough: fall.F{Zones: []string{"."}},
|
||||
fall: fall.F{Zones: []string{"."}},
|
||||
zones: []string{"."},
|
||||
}
|
||||
brokenTemplate := template{
|
||||
|
@ -67,7 +66,7 @@ func TestHandler(t *testing.T) {
|
|||
answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }} 60 IN TXT \"{{ index .Match 2 }}\""))},
|
||||
qclass: dns.ClassANY,
|
||||
qtype: dns.TypeANY,
|
||||
fthrough: fall.F{Zones: []string{"."}},
|
||||
fall: fall.F{Zones: []string{"."}},
|
||||
zones: []string{"."},
|
||||
}
|
||||
nonRRTemplate := template{
|
||||
|
@ -75,7 +74,7 @@ func TestHandler(t *testing.T) {
|
|||
answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }}"))},
|
||||
qclass: dns.ClassANY,
|
||||
qtype: dns.TypeANY,
|
||||
fthrough: fall.F{Zones: []string{"."}},
|
||||
fall: fall.F{Zones: []string{"."}},
|
||||
zones: []string{"."},
|
||||
}
|
||||
nonRRAdditionalTemplate := template{
|
||||
|
@ -83,7 +82,7 @@ func TestHandler(t *testing.T) {
|
|||
additional: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }}"))},
|
||||
qclass: dns.ClassANY,
|
||||
qtype: dns.TypeANY,
|
||||
fthrough: fall.F{Zones: []string{"."}},
|
||||
fall: fall.F{Zones: []string{"."}},
|
||||
zones: []string{"."},
|
||||
}
|
||||
nonRRAuthoritativeTemplate := template{
|
||||
|
@ -91,7 +90,7 @@ func TestHandler(t *testing.T) {
|
|||
authority: []*gotmpl.Template{gotmpl.Must(gotmpl.New("authority").Parse("{{ .Name }}"))},
|
||||
qclass: dns.ClassANY,
|
||||
qtype: dns.TypeANY,
|
||||
fthrough: fall.F{Zones: []string{"."}},
|
||||
fall: fall.F{Zones: []string{"."}},
|
||||
zones: []string{"."},
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue