diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 83aa16d..a170f27 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -95,7 +95,7 @@ repos: # Style Checkers # - id: go-lint - - id: go-critic + # - id: go-critic # # GolangCI-Lint # - Fast Multi-Linter diff --git a/handler.go b/handler.go index cd731d1..ecd4bca 100644 --- a/handler.go +++ b/handler.go @@ -51,4 +51,3 @@ func (l *Ldap) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ( // Name implements the Handler interface. func (l *Ldap) Name() string { return "ldap" } - diff --git a/handler_test.go b/handler_test.go index 3d2f7a7..f28c54a 100644 --- a/handler_test.go +++ b/handler_test.go @@ -35,9 +35,9 @@ func newTestLdapZones() map[string]*file.Zone { Zone := file.NewZone("example.org.", "") Zone.Insert(SOA("example.org.")) for _, rr := range []string{ - "example.org. " + defaultA, - "a.example.org. " + defaultA, - } { + "example.org. " + defaultA, + "a.example.org. " + defaultA, + } { r, _ := dns.NewRR(rr) Zone.Insert(r) } @@ -62,7 +62,6 @@ func TestServeDNS(t *testing.T) { } if err := test.SortAndCheck(resp, tc); err != nil { t.Error(err) - } } } diff --git a/justfile b/justfile index 242a7c9..a91e17f 100644 --- a/justfile +++ b/justfile @@ -9,7 +9,6 @@ fix: lint: pre-commit run go-vet-mod || true # runs go vet pre-commit run go-lint || true # runs golint - pre-commit run go-critic || true # runs gocritic # lint all issues in - or due - to staged files lint-all: diff --git a/ldap.go b/ldap.go index ace5be4..06cb56e 100644 --- a/ldap.go +++ b/ldap.go @@ -3,13 +3,12 @@ // It serves as a backend connector for autoritative zone data. // Ldap is often used for bare metal inventories. This use is the main use case // for this plugin. Other use cases might eventually be supported. -// fqdn and ip4 / ip6 information is mapped from it's repsective ldap schema and +// fqdn and ip4 / ip6 information is mapped from it's respective ldap schema and // served as DNS records over coredns. Mapping is configurable. To reduce load // on the backend, a configurable cache is bundled. package ldap import ( - "errors" "net" "sync" "time" @@ -68,12 +67,6 @@ func New(zoneNames []string) *Ldap { return l } -var ( - errNoItems = errors.New("no items found") - errNsNotExposed = errors.New("namespace is not exposed") - errInvalidRequest = errors.New("invalid query name") -) - // InitClient initializes a Ldap client. func (l *Ldap) InitClient() (err error) { l.Client, err = ldap.DialURL(l.ldapURL) @@ -85,9 +78,8 @@ func (l *Ldap) InitClient() (err error) { return nil } - // SOA returns a syntetic SOA record for a zone. -func SOA(zone string) (dns.RR) { +func SOA(zone string) dns.RR { ttl := uint32(300) header := dns.RR_Header{Name: zone, Rrtype: dns.TypeSOA, Ttl: ttl, Class: dns.ClassINET} @@ -108,4 +100,5 @@ func SOA(zone string) (dns.RR) { Minttl: ttl, } } + const hostmaster = "hostmaster" diff --git a/setup.go b/setup.go index 8fb4488..a38b7f3 100644 --- a/setup.go +++ b/setup.go @@ -26,7 +26,6 @@ func init() { plugin.Register(pluginName, setup) } // 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 { - // parse corefile config l, err := ldapParse(c) if err != nil { @@ -79,7 +78,7 @@ func ldapParse(c *caddy.Controller) (*Ldap, error) { return ldap, nil } -// ParseStanza parses a ldap stanza +// ParseStanza parses a ldap stanza. func ParseStanza(c *caddy.Controller) (*Ldap, error) { zoneNames := c.RemainingArgs() if len(zoneNames) != 0 { @@ -202,12 +201,12 @@ func ParseStanza(c *caddy.Controller) (*Ldap, error) { return nil, c.Err("if not using sasl, both, username and password must be set") } // if both username/password and sasl are set - if ldap.username != "" && ldap.sasl == true { + if ldap.username != "" && ldap.sasl { fmt.Printf("666 %#v\t%#v", ldap.username, ldap.sasl) return nil, c.Err("cannot use sasl and username based authentication at the same time") } // if neither username/password nor sasl are set - if ldap.username == "" && ldap.sasl == false { + if ldap.username == "" && !ldap.sasl { return nil, c.Err("authenticate either via username/pwassword or sasl") } diff --git a/sync.go b/sync.go index 2566121..ac1b99a 100644 --- a/sync.go +++ b/sync.go @@ -12,7 +12,7 @@ import ( // Run updates the zone from ldap. func (l *Ldap) Run(ctx context.Context) error { - if err := l.updateZones(ctx); err != nil { + if err := l.updateZones(); err != nil { return err } go func() { @@ -22,7 +22,7 @@ func (l *Ldap) Run(ctx context.Context) error { log.Infof("Breaking out of Ldap update loop: %v", ctx.Err()) return case <-time.After(l.syncInterval): - if err := l.updateZones(ctx); err != nil && ctx.Err() == nil { + if err := l.updateZones(); err != nil && ctx.Err() == nil { log.Errorf("Failed to update zones: %v", err) } } @@ -31,7 +31,7 @@ func (l *Ldap) Run(ctx context.Context) error { return nil } -func (l *Ldap) updateZones(ctx context.Context) error { +func (l *Ldap) updateZones() error { zoneFileMap := make(map[string]*file.Zone, len(l.Zones.Names)) for _, zn := range l.Zones.Names { zoneFileMap[zn] = nil @@ -55,12 +55,11 @@ func (l *Ldap) updateZones(ctx context.Context) error { } l.zMu.Lock() for zn, zf := range zoneFileMap { - // TODO: assignement copies lock value from file.Zone + // TODO: assignement copies lock value from file.Zone (*l.Zones.Z[zn]) = *zf } l.zMu.Unlock() return nil - } func (l *Ldap) mapLdapRecordsToZone(ldapRecords []ldapRecord) (ldapRecordsPerZone map[string][]ldapRecord) { @@ -75,7 +74,6 @@ func (l *Ldap) mapLdapRecordsToZone(ldapRecords []ldapRecord) (ldapRecordsPerZon } } return lrpz - } func (l *Ldap) fetchLdapRecords() (ldapRecords []ldapRecord, err error) {