fix: lock value assingments & simplifications

This commit is contained in:
David Arnold 2020-06-09 23:00:48 -05:00
parent 558ebb0127
commit 5e1200ef9b
No known key found for this signature in database
GPG Key ID: 6D6A936E69C59D08
3 changed files with 6 additions and 7 deletions

View File

@ -11,7 +11,7 @@ import (
) )
// ServeDNS implements the plugin.Handler interface. // ServeDNS implements the plugin.Handler interface.
func (l Ldap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { func (l *Ldap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
// opt := plugin.Options{} // opt := plugin.Options{}
state := request.Request{W: w, Req: r} state := request.Request{W: w, Req: r}
@ -50,5 +50,5 @@ func (l Ldap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
} }
// Name implements the Handler interface. // Name implements the Handler interface.
func (l Ldap) Name() string { return "ldap" } func (l *Ldap) Name() string { return "ldap" }

View File

@ -2,4 +2,4 @@ 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 (l Ldap) Ready() bool { return true } func (l *Ldap) Ready() bool { return true }

View File

@ -10,7 +10,6 @@ import (
"github.com/coredns/coredns/plugin/file" "github.com/coredns/coredns/plugin/file"
) )
// Run updates the zone from ldap. // Run updates the zone from ldap.
func (l *Ldap) Run(ctx context.Context) error { func (l *Ldap) Run(ctx context.Context) error {
if err := l.updateZones(ctx); err != nil { if err := l.updateZones(ctx); err != nil {
@ -56,6 +55,7 @@ func (l *Ldap) updateZones(ctx context.Context) error {
} }
l.zMu.Lock() l.zMu.Lock()
for zn, zf := range zoneFileMap { for zn, zf := range zoneFileMap {
// TODO: assignement copies lock value from file.Zone
(*l.Zones.Z[zn]) = *zf (*l.Zones.Z[zn]) = *zf
} }
l.zMu.Unlock() l.zMu.Unlock()
@ -84,7 +84,7 @@ func (l *Ldap) fetchLdapRecords() (ldapRecords []ldapRecord, err error) {
return nil, fmt.Errorf("fetching data from server: %w", err) return nil, fmt.Errorf("fetching data from server: %w", err)
} }
ldapRecords = make([]ldapRecord, len(searchResult.Entries)) ldapRecords = make([]ldapRecord, len(searchResult.Entries))
for i, _ := range ldapRecords { for i := 0; i < len(ldapRecords); i++ {
ldapRecords[i] = ldapRecord{ ldapRecords[i] = ldapRecord{
fqdn: searchResult.Entries[i].GetAttributeValue(l.fqdnAttr), fqdn: searchResult.Entries[i].GetAttributeValue(l.fqdnAttr),
ip: net.ParseIP(searchResult.Entries[i].GetAttributeValue(l.ip4Attr)), ip: net.ParseIP(searchResult.Entries[i].GetAttributeValue(l.ip4Attr)),
@ -92,4 +92,3 @@ func (l *Ldap) fetchLdapRecords() (ldapRecords []ldapRecord, err error) {
} }
return ldapRecords, nil return ldapRecords, nil
} }