renaming stuff

This commit is contained in:
David Arnold 2020-06-01 02:48:07 -05:00
parent 791558543c
commit 55900c99c2
No known key found for this signature in database
GPG Key ID: 6D6A936E69C59D08
7 changed files with 46 additions and 47 deletions

View File

@ -1,13 +1,12 @@
# example
# ldap
## Name
*example* - prints "example" on every query handled.
*ldap* - serves a zone from a ldap backend.
## Description
The example plugin prints "example" on every query that go handled by the server. It serves as
documentation for writing CoreDNS plugins.
The ldap plugin resolve A, AAAA y PTR RR from ldap backend. To reduce load on the backend, you can configure `cacheTimeout=30m`.
## Compilation
@ -18,7 +17,7 @@ The [manual](https://coredns.io/manual/toc/#what-is-coredns) will have more info
A simple way to consume this plugin, is by adding the following on [plugin.cfg](https://github.com/coredns/coredns/blob/master/plugin.cfg), and recompile it as [detailed on coredns.io](https://coredns.io/2017/07/25/compile-time-enabling-or-disabling-plugins/#build-with-compile-time-configuration-file).
~~~
example:github.com/coredns/example
ldap:github.com/xoe-labs/ldap
~~~
After this you can compile coredns by:
@ -37,14 +36,14 @@ make
## Syntax
~~~ txt
example
ldap
~~~
## Metrics
If monitoring is enabled (via the *prometheus* directive) the following metric is exported:
* `coredns_example_request_count_total{server}` - query count to the *example* plugin.
* `coredns_ldap_request_count_total{server}` - query count to the *ldap* plugin.
The `server` label indicated which server handled the request, see the *metrics* plugin for details.
@ -54,13 +53,13 @@ This plugin reports readiness to the ready plugin. It will be immediately ready.
## Examples
In this configuration, we forward all queries to 9.9.9.9 and print "example" whenever we receive
In this configuration, we forward all queries to 9.9.9.9 and print "ldap" whenever we receive
a query.
~~~ corefile
. {
forward . 9.9.9.9
example
ldap
}
~~~

View File

@ -1,7 +1,7 @@
// Package example is a CoreDNS plugin that prints "example" to stdout on every packet received.
// Package ldap is a CoreDNS plugin that prints "ldap" to stdout on every packet received.
//
// It serves as an example CoreDNS plugin with numerous code comments.
package example
// It serves as an ldap CoreDNS plugin with numerous code comments.
package ldap
import (
"context"
@ -18,20 +18,20 @@ import (
// Define log to be a logger with the plugin name in it. This way we can just use log.Info and
// friends to log.
var log = clog.NewWithPlugin("example")
var log = clog.NewWithPlugin("ldap")
// Example is an example plugin to show how to write a plugin.
type Example struct {
// Ldap is an ldap plugin to show how to write a plugin.
type Ldap struct {
Next plugin.Handler
}
// ServeDNS implements the plugin.Handler interface. This method gets called when example is used
// ServeDNS implements the plugin.Handler interface. This method gets called when ldap is used
// in a Server.
func (e Example) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
// This function could be simpler. I.e. just fmt.Println("example") here, but we want to show
// a slightly more complex example as to make this more interesting.
func (e Ldap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
// This function could be simpler. I.e. just fmt.Println("ldap") here, but we want to show
// a slightly more complex ldap as to make this more interesting.
// Here we wrap the dns.ResponseWriter in a new ResponseWriter and call the next plugin, when the
// answer comes back, it will print "example".
// answer comes back, it will print "ldap".
// Debug log that we've have seen the query. This will only be shown when the debug plugin is loaded.
log.Debug("Received response")
@ -47,9 +47,9 @@ func (e Example) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
}
// Name implements the Handler interface.
func (e Example) Name() string { return "example" }
func (e Ldap) Name() string { return "ldap" }
// ResponsePrinter wrap a dns.ResponseWriter and will write example to standard output when WriteMsg is called.
// ResponsePrinter wrap a dns.ResponseWriter and will write ldap to standard output when WriteMsg is called.
type ResponsePrinter struct {
dns.ResponseWriter
}
@ -59,9 +59,9 @@ func NewResponsePrinter(w dns.ResponseWriter) *ResponsePrinter {
return &ResponsePrinter{ResponseWriter: w}
}
// WriteMsg calls the underlying ResponseWriter's WriteMsg method and prints "example" to standard output.
// WriteMsg calls the underlying ResponseWriter's WriteMsg method and prints "ldap" to standard output.
func (r *ResponsePrinter) WriteMsg(res *dns.Msg) error {
fmt.Fprintln(out, "example")
fmt.Fprintln(out, "ldap")
return r.ResponseWriter.WriteMsg(res)
}

View File

@ -1,4 +1,4 @@
package example
package ldap
import (
"bytes"
@ -11,25 +11,25 @@ import (
"github.com/miekg/dns"
)
func TestExample(t *testing.T) {
// Create a new Example Plugin. Use the test.ErrorHandler as the next plugin.
x := Example{Next: test.ErrorHandler()}
func TestLdap(t *testing.T) {
// Create a new Ldap Plugin. Use the test.ErrorHandler as the next plugin.
x := Ldap{Next: test.ErrorHandler()}
// Setup a new output buffer that is *not* standard output, so we can check if
// example is really being printed.
// ldap is really being printed.
b := &bytes.Buffer{}
out = b
ctx := context.TODO()
r := new(dns.Msg)
r.SetQuestion("example.org.", dns.TypeA)
r.SetQuestion("ldap.org.", dns.TypeA)
// Create a new Recorder that captures the result, this isn't actually used in this test
// as it just serves as something that implements the dns.ResponseWriter interface.
rec := dnstest.NewRecorder(&test.ResponseWriter{})
// Call our plugin directly, and check the result.
x.ServeDNS(ctx, rec, r)
if a := b.String(); a != "example\n" {
t.Errorf("Failed to print '%s', got %s", example, a)
if a := b.String(); a != "ldap\n" {
t.Errorf("Failed to print '%s', got %s", ldap, a)
}
}

View File

@ -1,4 +1,4 @@
package example
package ldap
import (
"sync"
@ -8,10 +8,10 @@ import (
"github.com/prometheus/client_golang/prometheus"
)
// requestCount exports a prometheus metric that is incremented every time a query is seen by the example plugin.
// requestCount exports a prometheus metric that is incremented every time a query is seen by the ldap plugin.
var requestCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "example",
Subsystem: "ldap",
Name: "request_count_total",
Help: "Counter of requests made.",
}, []string{"server"})

View File

@ -1,5 +1,5 @@
package example
package ldap
// Ready implements the ready.Readiness interface, once this flips to true CoreDNS
// assumes this plugin is ready for queries; it is not checked again.
func (e Example) Ready() bool { return true }
func (e Ldap) Ready() bool { return true }

View File

@ -1,4 +1,4 @@
package example
package ldap
import (
"github.com/coredns/coredns/core/dnsserver"
@ -9,17 +9,17 @@ import (
)
// init registers this plugin.
func init() { plugin.Register("example", setup) }
func init() { plugin.Register("ldap", setup) }
// setup is the function that gets called when the config parser see the token "example". Setup is responsible
// for parsing any extra options the example plugin may have. The first token this function sees is "example".
// setup is the function that gets called when the config parser see the token "ldap". Setup is responsible
// for parsing any extra options the ldap plugin may have. The first token this function sees is "ldap".
func setup(c *caddy.Controller) error {
c.Next() // Ignore "example" and give us the next token.
c.Next() // Ignore "ldap" and give us the next token.
if c.NextArg() {
// If there was another token, return an error, because we don't have any configuration.
// Any errors returned from this setup function should be wrapped with plugin.Error, so we
// can present a slightly nicer error message to the user.
return plugin.Error("example", c.ArgErr())
return plugin.Error("ldap", c.ArgErr())
}
// Add a startup function that will -- after all plugins have been loaded -- check if the
@ -32,7 +32,7 @@ func setup(c *caddy.Controller) error {
// 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 Example{Next: next}
return Ldap{Next: next}
})
// All OK, return a nil error.

View File

@ -1,4 +1,4 @@
package example
package ldap
import (
"testing"
@ -9,12 +9,12 @@ import (
// TestSetup tests the various things that should be parsed by setup.
// Make sure you also test for parse errors.
func TestSetup(t *testing.T) {
c := caddy.NewTestController("dns", `example`)
c := caddy.NewTestController("dns", `ldap`)
if err := setup(c); err != nil {
t.Fatalf("Expected no errors, but got: %v", err)
}
c = caddy.NewTestController("dns", `example more`)
c = caddy.NewTestController("dns", `ldap more`)
if err := setup(c); err == nil {
t.Fatalf("Expected errors, but got: %v", err)
}