From 0865a9015eae3b325669732237cdbe610a4f14c0 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Wed, 10 Jun 2020 03:03:59 -0500 Subject: [PATCH] lint: additional linting & nolints --- handler.go | 5 ++++- handler_test.go | 9 +++++++-- ldap.go | 2 +- setup.go | 4 ++++ sync.go | 11 +++++++++-- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/handler.go b/handler.go index fd391f0..fd87946 100644 --- a/handler.go +++ b/handler.go @@ -49,7 +49,10 @@ func (l *Ldap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ( case file.ServerFailure: return dns.RcodeServerFailure, nil } - w.WriteMsg(m) + + if err := w.WriteMsg(m); err != nil { + return dns.RcodeServerFailure, nil + } return dns.RcodeSuccess, nil } diff --git a/handler_test.go b/handler_test.go index 3ea2e9b..93598a5 100644 --- a/handler_test.go +++ b/handler_test.go @@ -14,6 +14,7 @@ import ( . "github.com/xoe-labs/ldap/v0" ) +// nolint: gochecknoglobals var ldapTestCases = []test.Case{ { // Simple case @@ -36,14 +37,18 @@ func newTestLdap() *Ldap { func newTestLdapZones() map[string]*file.Zone { Zone := file.NewZone("example.org.", "") - Zone.Insert(SOA("example.org.")) + if err := Zone.Insert(SOA("example.org.")); err != nil { + panic("omg") + } for _, rr := range []string{ "example.org. " + defaultA, "a.example.org. " + defaultA, } { r, _ := dns.NewRR(rr) - Zone.Insert(r) + if err := Zone.Insert(r); err != nil { + panic("omg") + } } zones := make(map[string]*file.Zone) diff --git a/ldap.go b/ldap.go index 6839343..186ebce 100644 --- a/ldap.go +++ b/ldap.go @@ -27,7 +27,7 @@ type ldapRecord struct { ip net.IP } -func (r *ldapRecord) A() (A *dns.A) { +func (r *ldapRecord) A() (a *dns.A) { return &dns.A{Hdr: dns.RR_Header{Name: r.fqdn, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}, A: r.ip} } diff --git a/setup.go b/setup.go index 690c1e4..4083726 100644 --- a/setup.go +++ b/setup.go @@ -18,9 +18,11 @@ import ( const pluginName = "ldap" // Define log to be a logger with the plugin name in it. +// nolint: gochecknoglobals var log = clog.NewWithPlugin(pluginName) // init registers this plugin. +// nolint: gochecknoinits func init() { plugin.Register(pluginName, setup) } // setup is the function that gets called when the config parser see the token "ldap". Setup is responsible @@ -55,6 +57,7 @@ func setup(c *caddy.Controller) error { return nil } +// nolint: gochecknoglobals var once sync.Once func ldapParse(c *caddy.Controller) (*Ldap, error) { @@ -80,6 +83,7 @@ func ldapParse(c *caddy.Controller) (*Ldap, error) { } // ParseStanza parses a ldap stanza. +// nolint: funlen, gocognit, gocyclo func ParseStanza(c *caddy.Controller) (*Ldap, error) { zoneNames := c.RemainingArgs() if len(zoneNames) != 0 { diff --git a/sync.go b/sync.go index e0e0d06..d735e16 100644 --- a/sync.go +++ b/sync.go @@ -53,11 +53,18 @@ func (l *Ldap) updateZones() error { if zoneFileMap[zn] == nil { zoneFileMap[zn] = file.NewZone(zn, "") zoneFileMap[zn].Upstream = l.Upstream - zoneFileMap[zn].Insert(SOA(zn)) + + err = zoneFileMap[zn].Insert(SOA(zn)) + if err != nil { + return fmt.Errorf("updating zones: %w", err) + } } for _, lr := range lrpz { - zoneFileMap[zn].Insert(lr.A()) + err = zoneFileMap[zn].Insert(lr.A()) + if err != nil { + return fmt.Errorf("updating zones: %w", err) + } } }