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 ## Name
*example* - prints "example" on every query handled. *ldap* - serves a zone from a ldap backend.
## Description ## Description
The example plugin prints "example" on every query that go handled by the server. It serves as The ldap plugin resolve A, AAAA y PTR RR from ldap backend. To reduce load on the backend, you can configure `cacheTimeout=30m`.
documentation for writing CoreDNS plugins.
## Compilation ## 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). 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: After this you can compile coredns by:
@ -37,14 +36,14 @@ make
## Syntax ## Syntax
~~~ txt ~~~ txt
example ldap
~~~ ~~~
## Metrics ## Metrics
If monitoring is enabled (via the *prometheus* directive) the following metric is exported: 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. 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 ## 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. a query.
~~~ corefile ~~~ corefile
. { . {
forward . 9.9.9.9 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. // It serves as an ldap CoreDNS plugin with numerous code comments.
package example package ldap
import ( import (
"context" "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 // Define log to be a logger with the plugin name in it. This way we can just use log.Info and
// friends to log. // 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. // Ldap is an ldap plugin to show how to write a plugin.
type Example struct { type Ldap struct {
Next plugin.Handler 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. // in a Server.
func (e Example) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { 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("example") here, but we want to show // This function could be simpler. I.e. just fmt.Println("ldap") here, but we want to show
// a slightly more complex example as to make this more interesting. // 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 // 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. // Debug log that we've have seen the query. This will only be shown when the debug plugin is loaded.
log.Debug("Received response") 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. // 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 { type ResponsePrinter struct {
dns.ResponseWriter dns.ResponseWriter
} }
@ -59,9 +59,9 @@ func NewResponsePrinter(w dns.ResponseWriter) *ResponsePrinter {
return &ResponsePrinter{ResponseWriter: w} 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 { func (r *ResponsePrinter) WriteMsg(res *dns.Msg) error {
fmt.Fprintln(out, "example") fmt.Fprintln(out, "ldap")
return r.ResponseWriter.WriteMsg(res) return r.ResponseWriter.WriteMsg(res)
} }

View File

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

View File

@ -1,4 +1,4 @@
package example package ldap
import ( import (
"sync" "sync"
@ -8,10 +8,10 @@ import (
"github.com/prometheus/client_golang/prometheus" "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{ var requestCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "example", Subsystem: "ldap",
Name: "request_count_total", Name: "request_count_total",
Help: "Counter of requests made.", Help: "Counter of requests made.",
}, []string{"server"}) }, []string{"server"})

View File

@ -1,5 +1,5 @@
package example package ldap
// Ready implements the ready.Readiness interface, once this flips to true CoreDNS // Ready implements the ready.Readiness interface, once this flips to true CoreDNS
// assumes this plugin is ready for queries; it is not checked again. // 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 ( import (
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
@ -9,17 +9,17 @@ import (
) )
// init registers this plugin. // 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 // setup is the function that gets called when the config parser see the token "ldap". Setup is responsible
// for parsing any extra options the example plugin may have. The first token this function sees is "example". // for parsing any extra options the ldap plugin may have. The first token this function sees is "ldap".
func setup(c *caddy.Controller) error { 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 c.NextArg() {
// If there was another token, return an error, because we don't have any configuration. // 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 // 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. // 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 // 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. // Add the Plugin to CoreDNS, so Servers can use it in their plugin chain.
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler { dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
return Example{Next: next} return Ldap{Next: next}
}) })
// All OK, return a nil error. // All OK, return a nil error.

View File

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