From 9963322fb684bb3b383c6ede2b2bde5094a1e1d1 Mon Sep 17 00:00:00 2001 From: Jordan Whited Date: Wed, 13 May 2020 11:48:30 -0700 Subject: [PATCH] implement config parsing --- setup.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/setup.go b/setup.go index 76f82bc..86fae5f 100644 --- a/setup.go +++ b/setup.go @@ -6,6 +6,7 @@ import ( "github.com/caddyserver/caddy" "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" + "github.com/miekg/dns" "golang.zx2c4.com/wireguard/wgctrl" ) @@ -14,19 +15,38 @@ func init() { } func setup(c *caddy.Controller) error { + c.Next() // Ignore "wgsd" and give us the next token. + + // return an error if there is no zone specified + if !c.NextArg() { + return plugin.Error("wgsd", c.ArgErr()) + } + zone := dns.Fqdn(c.Val()) + + // return an error if there is no device name specified + if !c.NextArg() { + return plugin.Error("wgsd", c.ArgErr()) + } + device := c.Val() + + // return an error if there are more tokens on this line + if c.NextArg() { + return plugin.Error("wgsd", c.ArgErr()) + } + client, err := wgctrl.New() if err != nil { return fmt.Errorf("wgsd: error constructing wgctrl client: %v", err) } - // TODO: parse zone and wireguard device name from config - // Add the Plugin to CoreDNS, so Servers can use it in their plugin chain. dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler { return &WGSD{ Next: next, client: client, + zone: zone, + device: device, } })