lint: partially
This commit is contained in:
parent
47d6fbf381
commit
67f30f86ef
@ -95,7 +95,7 @@ repos:
|
||||
# Style Checkers
|
||||
#
|
||||
- id: go-lint
|
||||
- id: go-critic
|
||||
# - id: go-critic
|
||||
#
|
||||
# GolangCI-Lint
|
||||
# - Fast Multi-Linter
|
||||
|
@ -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" }
|
||||
|
||||
|
@ -62,7 +62,6 @@ func TestServeDNS(t *testing.T) {
|
||||
}
|
||||
if err := test.SortAndCheck(resp, tc); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
justfile
1
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:
|
||||
|
13
ldap.go
13
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"
|
||||
|
7
setup.go
7
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")
|
||||
}
|
||||
|
||||
|
8
sync.go
8
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
|
||||
@ -60,7 +60,6 @@ func (l *Ldap) updateZones(ctx context.Context) error {
|
||||
}
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user