aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-09-05 09:32:11 +0100
committerGravatar GitHub <noreply@github.com> 2016-09-05 09:32:11 +0100
commiteea77cc97c5a9c8b6dc627cded263167e2da0efd (patch)
treed06bd297d79fe0745fdba5093cb5f0148d925ea5
parente750a4c1bde5e173b173a4b2d348d88a61f9caca (diff)
downloadcoredns-eea77cc97c5a9c8b6dc627cded263167e2da0efd.tar.gz
coredns-eea77cc97c5a9c8b6dc627cded263167e2da0efd.tar.zst
coredns-eea77cc97c5a9c8b6dc627cded263167e2da0efd.zip
Fs (#242)
* play around with fs idea * docs and fix test * better docs
-rw-r--r--middleware/dnssec/README.md2
-rw-r--r--middleware/fs.go45
-rw-r--r--middleware/fs_test.go19
3 files changed, 65 insertions, 1 deletions
diff --git a/middleware/dnssec/README.md b/middleware/dnssec/README.md
index c16b38583..794ec2194 100644
--- a/middleware/dnssec/README.md
+++ b/middleware/dnssec/README.md
@@ -17,7 +17,7 @@ signing operations are done online. Authenticated denial of existence is impleme
lies. Using ECDSA as an algorithm is preferred as this leads to smaller signatures (compared to
RSA). NSEC3 is *not* supported.
-A signing key can be specified by using the `key` directive.
+A single signing key can be specified by using the `key` directive.
NOTE: Key generation has not been implemented yet.
diff --git a/middleware/fs.go b/middleware/fs.go
new file mode 100644
index 000000000..5970d0e99
--- /dev/null
+++ b/middleware/fs.go
@@ -0,0 +1,45 @@
+package middleware
+
+import (
+ "net/http"
+ "os"
+ "path/filepath"
+ "runtime"
+)
+
+// dir wraps http.Dir that restrict file access to a specific directory tree.
+type dir http.Dir
+
+// CoreDir is the directory where middleware can store assets, like zone files after a zone transfer
+// or public and private keys or anything else a middleware might need. The convention is to place
+// assets in a subdirectory named after the fully qualified zone.
+//
+// example.org./Kexample<something>.key
+//
+// CoreDir will default to "$HOME/.coredns" on Unix, but it's location can be overriden with the COREDNSPATH
+// environment variable.
+var CoreDir dir = dir(fsPath())
+
+// fsPath returns the path to the directory where the application may store data.
+// If COREDNSPATH env variable. is set, that value is used. Otherwise, the path is
+// the result of evaluating "$HOME/.coredns".
+func fsPath() string {
+ if corePath := os.Getenv("COREDNSPATH"); corePath != "" {
+ return corePath
+ }
+ return filepath.Join(userHomeDir(), ".coredns")
+}
+
+// userHomeDir returns the user's home directory according to environment variables.
+//
+// Credit: http://stackoverflow.com/a/7922977/1048862
+func userHomeDir() string {
+ if runtime.GOOS == "windows" {
+ home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
+ if home == "" {
+ home = os.Getenv("USERPROFILE")
+ }
+ return home
+ }
+ return os.Getenv("HOME")
+}
diff --git a/middleware/fs_test.go b/middleware/fs_test.go
new file mode 100644
index 000000000..44133c4eb
--- /dev/null
+++ b/middleware/fs_test.go
@@ -0,0 +1,19 @@
+package middleware
+
+import (
+ "os"
+ "strings"
+ "testing"
+)
+
+func TestfsPath(t *testing.T) {
+ if actual := fsPath(); !strings.HasSuffix(actual, ".coredns") {
+ t.Errorf("Expected path to be a .coredns folder, got: %v", actual)
+ }
+
+ os.Setenv("COREDNSPATH", "testpath")
+ defer os.Setenv("COREDNSPATH", "")
+ if actual, expected := fsPath(), "testpath"; actual != expected {
+ t.Errorf("Expected path to be %v, got: %v", expected, actual)
+ }
+}