aboutsummaryrefslogtreecommitdiff
path: root/plugin/pkg/fall/fall.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-01-07 16:32:59 +0000
committerGravatar GitHub <noreply@github.com> 2018-01-07 16:32:59 +0000
commitc6febe6250361eee580dbb8a601a444f23ed7ac2 (patch)
treeee81ab66cfa382d66bc085d31804efb8c1059af2 /plugin/pkg/fall/fall.go
parent84ebbbc7225a8d7eb5e00c0c525f7e12932a9fe4 (diff)
downloadcoredns-c6febe6250361eee580dbb8a601a444f23ed7ac2.tar.gz
coredns-c6febe6250361eee580dbb8a601a444f23ed7ac2.tar.zst
coredns-c6febe6250361eee580dbb8a601a444f23ed7ac2.zip
Add pkg/fall for Fallthrough (#1355)
* Add pkg/fall for Fallthrough Move this into it's own package to facilitate tests. Important bug was fixed: make the names fully qualified. Add fall package to hosts, reverse, etcd, and fix kubernetes and any tests. The k8s tests are still as-is, might need a future cleanup.
Diffstat (limited to 'plugin/pkg/fall/fall.go')
-rw-r--r--plugin/pkg/fall/fall.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/plugin/pkg/fall/fall.go b/plugin/pkg/fall/fall.go
new file mode 100644
index 000000000..99ad34618
--- /dev/null
+++ b/plugin/pkg/fall/fall.go
@@ -0,0 +1,77 @@
+// Package fall handles the fallthrough logic used in plugins that support it.
+package fall
+
+import (
+ "github.com/coredns/coredns/plugin"
+)
+
+// F can be nil to allow for no fallthrough, empty allow all zones to fallthrough or
+// contain a zone list that is checked.
+type F []string
+
+// New returns a new F.
+func New() *F { return new(F) }
+
+// Through will check if we should fallthrough for qname. Note that we've named the
+// variable in each plugin "Fall", so this then reads Fall.Through().
+func (f *F) Through(qname string) bool {
+ if f == nil {
+ return false
+ }
+ if len(*f) == 0 {
+ return true
+ }
+ zone := plugin.Zones(*f).Matches(qname)
+ return zone != ""
+}
+
+// SetZones will set zones in f.
+func (f *F) SetZones(zones []string) {
+ for i := range zones {
+ zones[i] = plugin.Host(zones[i]).Normalize()
+ }
+ *f = zones
+}
+
+// Example returns an F with example.org. as the zone name.
+var Example = func() *F {
+ f := F([]string{"example.org."})
+ return &f
+}()
+
+// Zero returns a zero valued F.
+var Zero = func() *F {
+ f := F([]string{})
+ return &f
+}
+
+// IsNil returns true is f is nil.
+func (f *F) IsNil() bool { return f == nil }
+
+// IsZero returns true is f is zero (and not nil).
+func (f *F) IsZero() bool {
+ if f == nil {
+ return false
+ }
+ return len(*f) == 0
+}
+
+// Equal returns true if f and g are equal. Only useful in tests, The (possible) zones
+// are *not* checked.
+func (f *F) Equal(g *F) bool {
+ if f.IsNil() {
+ if g.IsNil() {
+ return true
+ }
+ return false
+ }
+ if f.IsZero() {
+ if g.IsZero() {
+ return true
+ }
+ }
+ if len(*f) != len(*g) {
+ return false
+ }
+ return true
+}