From fff283269d9b9650bcc76efd302402ed1fc434dc Mon Sep 17 00:00:00 2001 From: Rene Kaufmann Date: Tue, 25 Oct 2016 10:11:52 +0200 Subject: [PATCH] updated easyKV --- .../HeavyHorst/easyKV/etcd/etcdv2/client.go | 2 +- .../HeavyHorst/easyKV/etcd/etcdv3/client.go | 2 +- .../HeavyHorst/easyKV/file/client.go | 12 ++++- .../HeavyHorst/easyKV/vault/client.go | 48 ++++++++++++++++++- vendor/vendor.json | 40 ++++++++-------- 5 files changed, 80 insertions(+), 24 deletions(-) diff --git a/vendor/github.com/HeavyHorst/easyKV/etcd/etcdv2/client.go b/vendor/github.com/HeavyHorst/easyKV/etcd/etcdv2/client.go index 3205f7b1..a9f77c92 100644 --- a/vendor/github.com/HeavyHorst/easyKV/etcd/etcdv2/client.go +++ b/vendor/github.com/HeavyHorst/easyKV/etcd/etcdv2/client.go @@ -159,7 +159,7 @@ func (c *Client) WatchPrefix(prefix string, stopChan chan bool, opts ...easyKV.W resp, err := watcher.Next(ctx) if err != nil { if err == context.Canceled { - return 0, easyKV.ErrWatchCanceled + return options.WaitIndex, easyKV.ErrWatchCanceled } switch e := err.(type) { case *client.Error: diff --git a/vendor/github.com/HeavyHorst/easyKV/etcd/etcdv3/client.go b/vendor/github.com/HeavyHorst/easyKV/etcd/etcdv3/client.go index 3b4ceda7..34742562 100644 --- a/vendor/github.com/HeavyHorst/easyKV/etcd/etcdv3/client.go +++ b/vendor/github.com/HeavyHorst/easyKV/etcd/etcdv3/client.go @@ -125,7 +125,7 @@ func (c *Client) WatchPrefix(prefix string, stopChan chan bool, opts ...easyKV.W } } if ctx.Err() == context.Canceled { - return 0, easyKV.ErrWatchCanceled + return options.WaitIndex, easyKV.ErrWatchCanceled } return 0, err } diff --git a/vendor/github.com/HeavyHorst/easyKV/file/client.go b/vendor/github.com/HeavyHorst/easyKV/file/client.go index 0f36115e..ae6a125b 100644 --- a/vendor/github.com/HeavyHorst/easyKV/file/client.go +++ b/vendor/github.com/HeavyHorst/easyKV/file/client.go @@ -10,6 +10,7 @@ package file import ( "io/ioutil" + "strings" "github.com/HeavyHorst/easyKV" "github.com/fsnotify/fsnotify" @@ -30,6 +31,7 @@ func New(filepath string) (*Client, error) { func (c *Client) GetValues(keys []string) (map[string]string, error) { yamlMap := make(map[interface{}]interface{}) vars := make(map[string]string) + kvs := make(map[string]string) data, err := ioutil.ReadFile(c.filepath) if err != nil { @@ -42,7 +44,15 @@ func (c *Client) GetValues(keys []string) (map[string]string, error) { nodeWalk(yamlMap, "", vars) - return vars, nil + for _, k := range keys { + for key, val := range vars { + if strings.HasPrefix(key, k) { + kvs[key] = val + } + } + } + + return kvs, nil } // Close closes the client connection diff --git a/vendor/github.com/HeavyHorst/easyKV/vault/client.go b/vendor/github.com/HeavyHorst/easyKV/vault/client.go index babd761e..236adc08 100644 --- a/vendor/github.com/HeavyHorst/easyKV/vault/client.go +++ b/vendor/github.com/HeavyHorst/easyKV/vault/client.go @@ -180,8 +180,14 @@ func (c *Client) Close() { // GetValues queries etcd for keys prefixed by prefix. func (c *Client) GetValues(keys []string) (map[string]string, error) { - vars := make(map[string]string) + branches := make(map[string]bool) + for _, key := range keys { + walkTree(c.client, key, branches) + } + + vars := make(map[string]string) + for key := range branches { resp, err := c.client.Logical().Read(key) if err != nil { @@ -201,11 +207,51 @@ func (c *Client) GetValues(keys []string) (map[string]string, error) { js, _ := json.Marshal(resp.Data) vars[key] = string(js) flatten(key, resp.Data, vars) + delete(vars, key) } } return vars, nil } +// recursively walk the branches in the Vault, adding to branches map +func walkTree(c *vaultapi.Client, key string, branches map[string]bool) error { + // strip trailing slash as long as it's not the only character + if last := len(key) - 1; last > 0 && key[last] == '/' { + key = key[:last] + } + + if branches[key] { + // already processed this branch + return nil + } + branches[key] = true + + resp, err := c.Logical().List(key) + if err != nil { + return err + } + if resp == nil || resp.Data == nil || resp.Data["keys"] == nil { + return nil + } + + switch resp.Data["keys"].(type) { + case []interface{}: + // expected + default: + return nil + } + + keyList := resp.Data["keys"].([]interface{}) + for _, innerKey := range keyList { + switch innerKey.(type) { + case string: + innerKey = path.Join(key, "/", innerKey.(string)) + walkTree(c, innerKey.(string), branches) + } + } + return nil +} + // isKV checks if a given map has only one key of type string // if so, returns the value of that key func isKV(data map[string]interface{}) (string, bool) { diff --git a/vendor/vendor.json b/vendor/vendor.json index 295452c1..044581a8 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -11,50 +11,50 @@ { "checksumSHA1": "Uq24NZHcsviyGg19iwymuu6hD2s=", "path": "github.com/HeavyHorst/easyKV/consul", - "revision": "1497d5b8d091b473a8d961488d8a1b689cfa75e5", - "revisionTime": "2016-10-20T17:49:10Z" + "revision": "37f72f9e3538376650a75265eec476ee227e732a", + "revisionTime": "2016-10-25T07:46:47Z" }, { "checksumSHA1": "WbtameMILRMLhqB+h3ADBFBoJGM=", "path": "github.com/HeavyHorst/easyKV/env", - "revision": "fc66e285b79a02b217971944ec2c8e0a35c686f0", - "revisionTime": "2016-10-01T10:35:50Z" + "revision": "37f72f9e3538376650a75265eec476ee227e732a", + "revisionTime": "2016-10-25T07:46:47Z" }, { "checksumSHA1": "FQfagzelDWm6GWBplwTVvUl6LMA=", "path": "github.com/HeavyHorst/easyKV/etcd", - "revision": "64024881db6b5968c90613c72b33ad4f9cf5122d", - "revisionTime": "2016-10-12T16:20:12Z" + "revision": "37f72f9e3538376650a75265eec476ee227e732a", + "revisionTime": "2016-10-25T07:46:47Z" }, { - "checksumSHA1": "SGx80zebNOAO4bd1Y52SHMT+MVw=", + "checksumSHA1": "CYczKYCTLQMXld9L4sCy5ujhGDc=", "path": "github.com/HeavyHorst/easyKV/etcd/etcdv2", - "revision": "1497d5b8d091b473a8d961488d8a1b689cfa75e5", - "revisionTime": "2016-10-20T17:49:10Z" + "revision": "37f72f9e3538376650a75265eec476ee227e732a", + "revisionTime": "2016-10-25T07:46:47Z" }, { - "checksumSHA1": "VXf+mVuOFnPWPkJHe5JGuHeYjD0=", + "checksumSHA1": "Ww2duzkVfHl/Cu8HjADRznztogw=", "path": "github.com/HeavyHorst/easyKV/etcd/etcdv3", - "revision": "64024881db6b5968c90613c72b33ad4f9cf5122d", - "revisionTime": "2016-10-12T16:20:12Z" + "revision": "37f72f9e3538376650a75265eec476ee227e732a", + "revisionTime": "2016-10-25T07:46:47Z" }, { - "checksumSHA1": "hRA8PwfiBgsA4NssqkPs8VwaJP0=", + "checksumSHA1": "3Jpnmdc6kxDB7Su6bezjol+TXiQ=", "path": "github.com/HeavyHorst/easyKV/file", - "revision": "1497d5b8d091b473a8d961488d8a1b689cfa75e5", - "revisionTime": "2016-10-20T17:49:10Z" + "revision": "37f72f9e3538376650a75265eec476ee227e732a", + "revisionTime": "2016-10-25T07:46:47Z" }, { "checksumSHA1": "+6G++DmodKHz7DNBRBWnt7CzJac=", "path": "github.com/HeavyHorst/easyKV/redis", - "revision": "fc66e285b79a02b217971944ec2c8e0a35c686f0", - "revisionTime": "2016-10-01T10:35:50Z" + "revision": "37f72f9e3538376650a75265eec476ee227e732a", + "revisionTime": "2016-10-25T07:46:47Z" }, { - "checksumSHA1": "d5FWIf/HRZBjshratAeKUu2mDW0=", + "checksumSHA1": "C3xV3wmwQkUyfrCxLDE8RqBobCU=", "path": "github.com/HeavyHorst/easyKV/vault", - "revision": "fc66e285b79a02b217971944ec2c8e0a35c686f0", - "revisionTime": "2016-10-01T10:35:50Z" + "revision": "37f72f9e3538376650a75265eec476ee227e732a", + "revisionTime": "2016-10-25T07:46:47Z" }, { "checksumSHA1": "NJO5YmTADjqj9WlHBcJ9trlEgNU=",