lint: additional linting & nolints

This commit is contained in:
David Arnold 2020-06-10 03:03:59 -05:00
parent 5209d31929
commit 0865a9015e
No known key found for this signature in database
GPG Key ID: 6D6A936E69C59D08
5 changed files with 25 additions and 6 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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}
}

View File

@ -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 {

11
sync.go
View File

@ -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)
}
}
}