From b4214b63d7c73cb0fec55b4e678a98327a159d48 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Sat, 4 Jan 2020 00:28:25 +0000 Subject: Refactor out of main a bit --- bind/config.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'bind') diff --git a/bind/config.go b/bind/config.go index 584b1ee..42b97cf 100644 --- a/bind/config.go +++ b/bind/config.go @@ -54,6 +54,25 @@ func (c *BINDConfig) Zone(view, name string) *Zone { return z } +// Find the closest zone that we manage by striping dotted components off the +// front of the domain until one matches. If there is a match return the zone +// that matched and any prefix components, if any, as a dotted string. If none +// match then return nil. +func (c *BINDConfig) FindClosestZone(zoneIn, view string) (*Zone, string) { + suffix := "" + prefix := []string{} + + zc := strings.Split(zoneIn, ".") + for i := 0; i <= len(zc)-2; i++ { + prefix, suffix = zc[:i], strings.Join(zc[i:], ".") + if zone := c.Zone(view, suffix); zone != nil { + return zone, strings.Join(prefix, ".") + } + } + + return nil, "" +} + func (c *BINDConfig) AddKey(k *Key) { c.keys[k.Name] = k } -- cgit v1.2.3