mirror of
https://github.com/coredns/coredns.git
synced 2025-11-29 07:04:08 -05:00
middleware/root: add it (#330)
This PR adds the *root* middleware that specifies a path where all zone file (the *file* middleware is the only consumer now) can be found. It works the same as in Caddy. Documentation can be found in the README.md of the middleware. Fixes #307
This commit is contained in:
@@ -13,7 +13,8 @@ zonefile.
|
||||
file DBFILE [ZONES...]
|
||||
~~~
|
||||
|
||||
* **DBFILE** the database file to read and parse.
|
||||
* **DBFILE** the database file to read and parse. If the path is relative the path from the *root*
|
||||
directive will be prepended to it.
|
||||
* **ZONES** zones it should be authoritative for. If empty, the zones from the configuration block
|
||||
are used.
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/miekg/coredns/core/dnsserver"
|
||||
"github.com/miekg/coredns/middleware"
|
||||
@@ -49,6 +50,8 @@ func fileParse(c *caddy.Controller) (Zones, error) {
|
||||
names := []string{}
|
||||
origins := []string{}
|
||||
|
||||
config := dnsserver.GetConfig(c)
|
||||
|
||||
for c.Next() {
|
||||
if c.Val() == "file" {
|
||||
// file db.file [zones...]
|
||||
@@ -64,6 +67,10 @@ func fileParse(c *caddy.Controller) (Zones, error) {
|
||||
origins = args
|
||||
}
|
||||
|
||||
if !path.IsAbs(fileName) && config.Root != "" {
|
||||
fileName = path.Join(config.Root, fileName)
|
||||
}
|
||||
|
||||
reader, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
// bail out
|
||||
|
||||
@@ -51,7 +51,7 @@ func TestFileParse(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
c := caddy.NewTestController("file", test.inputFileRules)
|
||||
c := caddy.NewTestController("dns", test.inputFileRules)
|
||||
actualZones, err := fileParse(c)
|
||||
|
||||
if err == nil && test.shouldErr {
|
||||
|
||||
Reference in New Issue
Block a user