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 /main.go | |
parent | dc3fd4df659bb35d7858714a429fc797bf5f1222 (diff) | |
download | bottin-1a20a64eff34336789c0e3b41db1de727e3fe998.tar.gz bottin-1a20a64eff34336789c0e3b41db1de727e3fe998.zip |
Refactoring
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 79 |
1 files changed, 0 insertions, 79 deletions
@@ -10,7 +10,6 @@ import ( "io/ioutil" "os" "os/signal" - "strings" "syscall" ldap "bottin/ldapserver" @@ -358,84 +357,6 @@ func (server *Server) init() error { return nil } -func (server *Server) putAttributes(dn string, attrs Entry) error { - prefix, err := dnToConsul(dn) - if err != nil { - return err - } - - for k, valuesNC := range attrs { - path := prefix + "/attribute=" + k - - // Trim spaces and remove empty values - values := []string{} - for _, v := range valuesNC { - vv := strings.TrimSpace(v) - if len(vv) > 0 { - values = append(values, vv) - } - } - - // If we have zero values, delete associated k/v pair - // Otherwise, write new values - if len(values) == 0 { - _, err := server.kv.Delete(path, nil) - if err != nil { - return err - } - } else { - json, err := json.MarshalIndent(values, "", " ") - if err != nil { - return err - } - pair := &consul.KVPair{Key: path, Value: json} - _, err = server.kv.Put(pair, nil) - if err != nil { - return err - } - } - } - return nil -} - -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 -} - func (server *Server) checkDN(dn string, allow_extend bool) (string, error) { // 1. Canonicalize: remove spaces between things and put all in lower case dn, err := canonicalDN(dn) |