From 55900c99c29c73163f718d786a2cf2249c4c1c37 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Mon, 1 Jun 2020 02:48:07 -0500 Subject: [PATCH] renaming stuff --- README.md | 17 ++++++++--------- example.go => ldap.go | 30 +++++++++++++++--------------- example_test.go => ldap_test.go | 16 ++++++++-------- metrics.go | 6 +++--- ready.go | 4 ++-- setup.go | 14 +++++++------- setup_test.go | 6 +++--- 7 files changed, 46 insertions(+), 47 deletions(-) rename example.go => ldap.go (62%) rename example_test.go => ldap_test.go (64%) diff --git a/README.md b/README.md index a575fbe..ff567b4 100644 --- a/README.md +++ b/README.md @@ -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 } ~~~ diff --git a/example.go b/ldap.go similarity index 62% rename from example.go rename to ldap.go index 9ccaad4..2a1374d 100644 --- a/example.go +++ b/ldap.go @@ -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) } diff --git a/example_test.go b/ldap_test.go similarity index 64% rename from example_test.go rename to ldap_test.go index 6b98814..66215d1 100644 --- a/example_test.go +++ b/ldap_test.go @@ -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) } } diff --git a/metrics.go b/metrics.go index d4b2d07..eb898e4 100644 --- a/metrics.go +++ b/metrics.go @@ -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"}) diff --git a/ready.go b/ready.go index 8175a9a..e8edb2a 100644 --- a/ready.go +++ b/ready.go @@ -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 } diff --git a/setup.go b/setup.go index 20c8fd9..d1455d0 100644 --- a/setup.go +++ b/setup.go @@ -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. diff --git a/setup_test.go b/setup_test.go index 5e708dd..b20f09d 100644 --- a/setup_test.go +++ b/setup_test.go @@ -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) }