lint: partially
This commit is contained in:
parent
47d6fbf381
commit
67f30f86ef
@ -95,7 +95,7 @@ repos:
|
|||||||
# Style Checkers
|
# Style Checkers
|
||||||
#
|
#
|
||||||
- id: go-lint
|
- id: go-lint
|
||||||
- id: go-critic
|
# - id: go-critic
|
||||||
#
|
#
|
||||||
# GolangCI-Lint
|
# GolangCI-Lint
|
||||||
# - Fast Multi-Linter
|
# - 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.
|
// Name implements the Handler interface.
|
||||||
func (l *Ldap) Name() string { return "ldap" }
|
func (l *Ldap) Name() string { return "ldap" }
|
||||||
|
|
||||||
|
@ -35,9 +35,9 @@ func newTestLdapZones() map[string]*file.Zone {
|
|||||||
Zone := file.NewZone("example.org.", "")
|
Zone := file.NewZone("example.org.", "")
|
||||||
Zone.Insert(SOA("example.org."))
|
Zone.Insert(SOA("example.org."))
|
||||||
for _, rr := range []string{
|
for _, rr := range []string{
|
||||||
"example.org. " + defaultA,
|
"example.org. " + defaultA,
|
||||||
"a.example.org. " + defaultA,
|
"a.example.org. " + defaultA,
|
||||||
} {
|
} {
|
||||||
r, _ := dns.NewRR(rr)
|
r, _ := dns.NewRR(rr)
|
||||||
Zone.Insert(r)
|
Zone.Insert(r)
|
||||||
}
|
}
|
||||||
@ -62,7 +62,6 @@ func TestServeDNS(t *testing.T) {
|
|||||||
}
|
}
|
||||||
if err := test.SortAndCheck(resp, tc); err != nil {
|
if err := test.SortAndCheck(resp, tc); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
justfile
1
justfile
@ -9,7 +9,6 @@ fix:
|
|||||||
lint:
|
lint:
|
||||||
pre-commit run go-vet-mod || true # runs go vet
|
pre-commit run go-vet-mod || true # runs go vet
|
||||||
pre-commit run go-lint || true # runs golint
|
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 issues in - or due - to staged files
|
||||||
lint-all:
|
lint-all:
|
||||||
|
13
ldap.go
13
ldap.go
@ -3,13 +3,12 @@
|
|||||||
// It serves as a backend connector for autoritative zone data.
|
// 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
|
// 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.
|
// 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
|
// served as DNS records over coredns. Mapping is configurable. To reduce load
|
||||||
// on the backend, a configurable cache is bundled.
|
// on the backend, a configurable cache is bundled.
|
||||||
package ldap
|
package ldap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -68,12 +67,6 @@ func New(zoneNames []string) *Ldap {
|
|||||||
return l
|
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.
|
// InitClient initializes a Ldap client.
|
||||||
func (l *Ldap) InitClient() (err error) {
|
func (l *Ldap) InitClient() (err error) {
|
||||||
l.Client, err = ldap.DialURL(l.ldapURL)
|
l.Client, err = ldap.DialURL(l.ldapURL)
|
||||||
@ -85,9 +78,8 @@ func (l *Ldap) InitClient() (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SOA returns a syntetic SOA record for a zone.
|
// SOA returns a syntetic SOA record for a zone.
|
||||||
func SOA(zone string) (dns.RR) {
|
func SOA(zone string) dns.RR {
|
||||||
ttl := uint32(300)
|
ttl := uint32(300)
|
||||||
header := dns.RR_Header{Name: zone, Rrtype: dns.TypeSOA, Ttl: ttl, Class: dns.ClassINET}
|
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,
|
Minttl: ttl,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const hostmaster = "hostmaster"
|
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
|
// 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".
|
// for parsing any extra options the ldap plugin may have. The first token this function sees is "ldap".
|
||||||
func setup(c *caddy.Controller) error {
|
func setup(c *caddy.Controller) error {
|
||||||
|
|
||||||
// parse corefile config
|
// parse corefile config
|
||||||
l, err := ldapParse(c)
|
l, err := ldapParse(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -79,7 +78,7 @@ func ldapParse(c *caddy.Controller) (*Ldap, error) {
|
|||||||
return ldap, nil
|
return ldap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseStanza parses a ldap stanza
|
// ParseStanza parses a ldap stanza.
|
||||||
func ParseStanza(c *caddy.Controller) (*Ldap, error) {
|
func ParseStanza(c *caddy.Controller) (*Ldap, error) {
|
||||||
zoneNames := c.RemainingArgs()
|
zoneNames := c.RemainingArgs()
|
||||||
if len(zoneNames) != 0 {
|
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")
|
return nil, c.Err("if not using sasl, both, username and password must be set")
|
||||||
}
|
}
|
||||||
// if both username/password and sasl are 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)
|
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")
|
return nil, c.Err("cannot use sasl and username based authentication at the same time")
|
||||||
}
|
}
|
||||||
// if neither username/password nor sasl are set
|
// 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")
|
return nil, c.Err("authenticate either via username/pwassword or sasl")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
sync.go
10
sync.go
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
// 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(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
go func() {
|
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())
|
log.Infof("Breaking out of Ldap update loop: %v", ctx.Err())
|
||||||
return
|
return
|
||||||
case <-time.After(l.syncInterval):
|
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)
|
log.Errorf("Failed to update zones: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ func (l *Ldap) Run(ctx context.Context) error {
|
|||||||
return nil
|
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))
|
zoneFileMap := make(map[string]*file.Zone, len(l.Zones.Names))
|
||||||
for _, zn := range l.Zones.Names {
|
for _, zn := range l.Zones.Names {
|
||||||
zoneFileMap[zn] = nil
|
zoneFileMap[zn] = nil
|
||||||
@ -55,12 +55,11 @@ 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
|
// TODO: assignement copies lock value from file.Zone
|
||||||
(*l.Zones.Z[zn]) = *zf
|
(*l.Zones.Z[zn]) = *zf
|
||||||
}
|
}
|
||||||
l.zMu.Unlock()
|
l.zMu.Unlock()
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Ldap) mapLdapRecordsToZone(ldapRecords []ldapRecord) (ldapRecordsPerZone map[string][]ldapRecord) {
|
func (l *Ldap) mapLdapRecordsToZone(ldapRecords []ldapRecord) (ldapRecordsPerZone map[string][]ldapRecord) {
|
||||||
@ -75,7 +74,6 @@ func (l *Ldap) mapLdapRecordsToZone(ldapRecords []ldapRecord) (ldapRecordsPerZon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lrpz
|
return lrpz
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Ldap) fetchLdapRecords() (ldapRecords []ldapRecord, err error) {
|
func (l *Ldap) fetchLdapRecords() (ldapRecords []ldapRecord, err error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user