aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/chaos/README.md2
-rw-r--r--plugin/chaos/chaos.go17
-rw-r--r--plugin/chaos/chaos_test.go2
-rw-r--r--plugin/chaos/setup.go34
-rw-r--r--plugin/chaos/setup_test.go12
-rw-r--r--plugin/chaos/zowners.go4
6 files changed, 43 insertions, 28 deletions
diff --git a/plugin/chaos/README.md b/plugin/chaos/README.md
index 8ddb2b0c7..3cd6dff41 100644
--- a/plugin/chaos/README.md
+++ b/plugin/chaos/README.md
@@ -16,7 +16,7 @@ chaos [VERSION] [AUTHORS...]
~~~
* **VERSION** is the version to return. Defaults to `CoreDNS-<version>`, if not set.
-* **AUTHORS** is what authors to return. No default.
+* **AUTHORS** is what authors to return. This defaults to all GitHub handles in the OWNERS files.
Note that you have to make sure that this plugin will get actual queries for the
following zones: `version.bind`, `version.server`, `authors.bind`, `hostname.bind` and
diff --git a/plugin/chaos/chaos.go b/plugin/chaos/chaos.go
index af76a0bcf..42b1fb3f0 100644
--- a/plugin/chaos/chaos.go
+++ b/plugin/chaos/chaos.go
@@ -16,7 +16,7 @@ import (
type Chaos struct {
Next plugin.Handler
Version string
- Authors map[string]struct{}
+ Authors []string
}
// ServeDNS implements the plugin.Handler interface.
@@ -32,13 +32,13 @@ func (c Chaos) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
hdr := dns.RR_Header{Name: state.QName(), Rrtype: dns.TypeTXT, Class: dns.ClassCHAOS, Ttl: 0}
switch state.Name() {
default:
- return c.Next.ServeDNS(ctx, w, r)
+ return plugin.NextOrFailure(c.Name(), c.Next, ctx, w, r)
case "authors.bind.":
- for a := range c.Authors {
- m.Answer = append(m.Answer, &dns.TXT{Hdr: hdr, Txt: []string{trim(a)}})
+ for _, a := range c.Authors {
+ m.Answer = append(m.Answer, &dns.TXT{Hdr: hdr, Txt: []string{a}})
}
case "version.bind.", "version.server.":
- m.Answer = []dns.RR{&dns.TXT{Hdr: hdr, Txt: []string{trim(c.Version)}}}
+ m.Answer = []dns.RR{&dns.TXT{Hdr: hdr, Txt: []string{c.Version}}}
case "hostname.bind.", "id.server.":
hostname, err := os.Hostname()
if err != nil {
@@ -52,10 +52,3 @@ func (c Chaos) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
// Name implements the Handler interface.
func (c Chaos) Name() string { return "chaos" }
-
-func trim(s string) string {
- if len(s) < 256 {
- return s
- }
- return s[:255]
-}
diff --git a/plugin/chaos/chaos_test.go b/plugin/chaos/chaos_test.go
index 179aab90c..12cc1697e 100644
--- a/plugin/chaos/chaos_test.go
+++ b/plugin/chaos/chaos_test.go
@@ -14,7 +14,7 @@ import (
func TestChaos(t *testing.T) {
em := Chaos{
Version: version,
- Authors: map[string]struct{}{"Miek Gieben": struct{}{}},
+ Authors: []string{"Miek Gieben"},
}
tests := []struct {
diff --git a/plugin/chaos/setup.go b/plugin/chaos/setup.go
index 8028876cf..6cf5e09da 100644
--- a/plugin/chaos/setup.go
+++ b/plugin/chaos/setup.go
@@ -1,6 +1,10 @@
+//go:generate go run owners_generate.go
+
package chaos
import (
+ "sort"
+
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
@@ -16,7 +20,7 @@ func init() {
}
func setup(c *caddy.Controller) error {
- version, authors, err := chaosParse(c)
+ version, authors, err := parse(c)
if err != nil {
return plugin.Error("chaos", err)
}
@@ -28,28 +32,42 @@ func setup(c *caddy.Controller) error {
return nil
}
-func chaosParse(c *caddy.Controller) (string, map[string]struct{}, error) {
+func parse(c *caddy.Controller) (string, []string, error) {
// Set here so we pick up AppName and AppVersion that get set in coremain's init().
chaosVersion = caddy.AppName + "-" + caddy.AppVersion
-
version := ""
- authors := make(map[string]struct{})
for c.Next() {
args := c.RemainingArgs()
if len(args) == 0 {
- return chaosVersion, nil, nil
+ return trim(chaosVersion), Owners, nil
}
if len(args) == 1 {
- return args[0], nil, nil
+ return trim(args[0]), Owners, nil
}
+
version = args[0]
+ authors := make(map[string]struct{})
for _, a := range args[1:] {
authors[a] = struct{}{}
}
- return version, authors, nil
+ list := []string{}
+ for k := range authors {
+ k = trim(k) // limit size to 255 chars
+ list = append(list, k)
+ }
+ sort.Strings(list)
+ return version, list, nil
+ }
+
+ return version, Owners, nil
+}
+
+func trim(s string) string {
+ if len(s) < 256 {
+ return s
}
- return version, authors, nil
+ return s[:255]
}
var chaosVersion string
diff --git a/plugin/chaos/setup_test.go b/plugin/chaos/setup_test.go
index 6f3c13fb3..b5cab4d29 100644
--- a/plugin/chaos/setup_test.go
+++ b/plugin/chaos/setup_test.go
@@ -12,7 +12,7 @@ func TestSetupChaos(t *testing.T) {
input string
shouldErr bool
expectedVersion string // expected version.
- expectedAuthor string // expected author (string, although we get a map).
+ expectedAuthor string // expected author (string, although we get a slice).
expectedErrContent string // substring from the expected error. Empty for positive cases.
}{
// positive
@@ -26,7 +26,7 @@ func TestSetupChaos(t *testing.T) {
for i, test := range tests {
c := caddy.NewTestController("dns", test.input)
- version, authors, err := chaosParse(c)
+ version, authors, err := parse(c)
if test.shouldErr && err == nil {
t.Errorf("Test %d: Expected error but found %s for input %s", i, err, test.input)
@@ -43,11 +43,11 @@ func TestSetupChaos(t *testing.T) {
}
if !test.shouldErr && version != test.expectedVersion {
- t.Errorf("Chaos not correctly set for input %s. Expected: %s, actual: %s", test.input, test.expectedVersion, version)
+ t.Errorf("Test %d: Chaos not correctly set for input %s. Expected: %s, actual: %s", i, test.input, test.expectedVersion, version)
}
- if !test.shouldErr && authors != nil {
- if _, ok := authors[test.expectedAuthor]; !ok {
- t.Errorf("Chaos not correctly set for input %s. Expected: '%s', actual: '%s'", test.input, test.expectedAuthor, "Miek Gieben")
+ if !test.shouldErr && authors != nil && test.expectedAuthor != "" {
+ if authors[0] != test.expectedAuthor {
+ t.Errorf("Test %d: Chaos not correctly set for input %s. Expected: '%s', actual: '%s'", i, test.input, test.expectedAuthor, authors[0])
}
}
}
diff --git a/plugin/chaos/zowners.go b/plugin/chaos/zowners.go
new file mode 100644
index 000000000..c3668600e
--- /dev/null
+++ b/plugin/chaos/zowners.go
@@ -0,0 +1,4 @@
+package chaos
+
+// Owners are all GitHub handlers of all maintainers.
+var Owners = []string{"bradbeam", "chrisohaver", "dilyevsky", "ekleiner", "fastest963", "fturib", "greenpau", "grobie", "inigohu", "isolus", "johnbelamaric", "miekg", "nchrisdk", "nitisht", "pmoroney", "rajansandeep", "rdrozhdzh", "rtreffer", "stp-ip", "superq", "varyoo", "yongtang"} \ No newline at end of file