cleanup recursive ldap group sync

This commit is contained in:
Christoph Haas
2022-12-27 13:25:28 +01:00
parent f2afd4a21c
commit 53a6602a64
3 changed files with 69 additions and 32 deletions

View File

@@ -8,11 +8,11 @@ import (
"github.com/pkg/errors"
)
type ObjectType int64
type ObjectType int
const (
Users ObjectType = 1
Groups ObjectType = 2
Users ObjectType = iota
Groups
)
type RawLdapData struct {
@@ -86,7 +86,8 @@ func FindAllObjects(cfg *Config, objType ObjectType) ([]RawLdapData, error) {
var searchRequest *ldap.SearchRequest
var attrs []string
if objType == Users {
switch objType {
case Users:
// Search all users
attrs = []string{"dn", cfg.EmailAttribute, cfg.EmailAttribute, cfg.FirstNameAttribute, cfg.LastNameAttribute,
cfg.PhoneAttribute, cfg.GroupMemberAttribute}
@@ -95,7 +96,7 @@ func FindAllObjects(cfg *Config, objType ObjectType) ([]RawLdapData, error) {
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
cfg.SyncFilter, attrs, nil,
)
} else if objType == Groups {
case Groups:
// Search all groups
attrs = []string{"dn", cfg.GroupMemberAttribute}
searchRequest = ldap.NewSearchRequest(
@@ -103,6 +104,8 @@ func FindAllObjects(cfg *Config, objType ObjectType) ([]RawLdapData, error) {
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
cfg.SyncGroupFilter, attrs, nil,
)
default:
panic("invalid object type")
}
sr, err := client.Search(searchRequest)