aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-01-20 09:11:30 +0100
committerAlex Auvolat <alex@adnab.me>2020-01-20 09:11:30 +0100
commita7ccdad378391d6d2f3585e35df84e6756bc90ca (patch)
tree59d79ecc77b4cefe1488ef14685b2989aaf6cdb4 /main.go
parent3b793c90a05e7e9b4ebd4ef998a80dc5ef7b5510 (diff)
downloadbottin-a7ccdad378391d6d2f3585e35df84e6756bc90ca.tar.gz
bottin-a7ccdad378391d6d2f3585e35df84e6756bc90ca.zip
Fix handling of empty set of values as absence of the key
Diffstat (limited to 'main.go')
-rw-r--r--main.go29
1 files changed, 19 insertions, 10 deletions
diff --git a/main.go b/main.go
index 713c697..f1be40a 100644
--- a/main.go
+++ b/main.go
@@ -246,14 +246,23 @@ func (server *Server) addElements(dn string, attrs Entry) error {
}
for k, v := range attrs {
- json, err := json.Marshal(v)
- if err != nil {
- return err
- }
- pair := &consul.KVPair{Key: prefix + "/attribute=" + k, Value: json}
- _, err = server.kv.Put(pair, nil)
- if err != nil {
- return err
+ path := prefix + "/attribute=" + k
+ if len(v) == 0 {
+ // If we have zero values, delete associated k/v pair
+ _, err := server.kv.Delete(path, nil)
+ if err != nil {
+ return err
+ }
+ } else {
+ json, err := json.Marshal(v)
+ 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
@@ -454,9 +463,9 @@ func applyFilter(entry Entry, filter message.Filter) (bool, error) {
} else if fPresent, ok := filter.(message.FilterPresent); ok {
what := string(fPresent)
// Case insensitive search
- for desc := range entry {
+ for desc, values := range entry {
if strings.EqualFold(what, desc) {
- return true, nil
+ return len(values) > 0, nil
}
}
return false, nil