diff options
author | Alex Auvolat <alex@adnab.me> | 2021-03-09 18:30:59 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-03-09 18:30:59 +0100 |
commit | 1a20a64eff34336789c0e3b41db1de727e3fe998 (patch) | |
tree | 27e32e575eeace4260f21f76969f6e1ab5c8b5c2 /read.go | |
parent | dc3fd4df659bb35d7858714a429fc797bf5f1222 (diff) | |
download | bottin-1a20a64eff34336789c0e3b41db1de727e3fe998.tar.gz bottin-1a20a64eff34336789c0e3b41db1de727e3fe998.zip |
Refactoring
Diffstat (limited to 'read.go')
-rw-r--r-- | read.go | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -9,6 +9,46 @@ import ( message "github.com/lor00x/goldap/message" ) +// Generic read utility functions ---------- + +func (server *Server) getAttribute(dn string, attr string) ([]string, error) { + path, err := dnToConsul(dn) + if err != nil { + return nil, err + } + + pairs, _, err := server.kv.List(path+"/attribute=", &server.readOpts) + if err != nil { + return nil, err + } + + values := []string{} + for _, pair := range pairs { + if strings.EqualFold(pair.Key, path+"/attribute="+attr) { + newVals, err := parseValue(pair.Value) + if err != nil { + return nil, err + } + values = append(values, newVals...) + } + } + + return values, nil +} + +func (server *Server) objectExists(dn string) (bool, error) { + prefix, err := dnToConsul(dn) + if err != nil { + return false, err + } + + data, _, err := server.kv.List(prefix+"/attribute=", &server.readOpts) + if err != nil { + return false, err + } + return len(data) > 0, nil +} + // Compare request ------------------------- func (server *Server) handleCompare(s ldap.UserState, w ldap.ResponseWriter, m *ldap.Message) { |