mirror of
https://github.com/h44z/wg-portal.git
synced 2025-10-04 15:36:18 +00:00
cleanup recursive ldap group sync
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user