From c91406c12af6a7882827793e65de70b88d972b81 Mon Sep 17 00:00:00 2001 From: Matthew Fisher Date: Wed, 26 Oct 2016 19:46:07 -0700 Subject: [PATCH] Revert "json-backend: tests and support for nested objects" This reverts commit efce8ea9d652eee709b3651903c39bd2e6724ef0. --- backends/json/client.go | 41 ++---------------------------------- config.go | 10 ++------- integration/json/sample.json | 30 -------------------------- integration/json/test.sh | 8 ------- 4 files changed, 4 insertions(+), 85 deletions(-) delete mode 100644 integration/json/sample.json delete mode 100755 integration/json/test.sh diff --git a/backends/json/client.go b/backends/json/client.go index f701153ff..30039f764 100644 --- a/backends/json/client.go +++ b/backends/json/client.go @@ -3,7 +3,6 @@ package json import ( "encoding/json" "io/ioutil" - "strings" ) // Client provides a shell for the json client @@ -20,7 +19,7 @@ func NewJsonClient(filePath string) (*Client, error) { return &Client{allJsonVars}, err } - err = json.Unmarshal(fileContents, &allJsonVars) + err = json.Unmarshal(fileContents, allJsonVars) if err != nil { return &Client{allJsonVars}, err } @@ -34,48 +33,12 @@ func (c *Client) GetValues(keys []string) (map[string]string, error) { vars := make(map[string]string) for _, key := range keys { - jsonWalk(c.data, key, vars) + vars[key] = c.data[key].(string) } return vars, nil } -// iterate over a json interface searching for key and add key/value to vars -func jsonWalk(json map[string]interface{}, key string, vars map[string]string) { - keyPath := strings.Split(strings.TrimPrefix(key, "/"), "/") - - for index, level := range keyPath { - if val, ok := json[level]; ok { - if index == len(keyPath)-1 { - if str, ok := val.(string); ok { - vars[key] = str - } else { - jsonAddAll( - vars, - strings.TrimPrefix(key, "/"), - val.(map[string]interface{})) - } - } else { - json = val.(map[string]interface{}) - } - } - } -} - -// iterate over a json interface adding all data and adding to vars -func jsonAddAll(vars map[string]string, keyPrefix string, json map[string]interface{}) { - for objkey, objvalue := range json { - if str, ok := objvalue.(string); ok { - vars[keyPrefix+"/"+objkey] = str - } else { - jsonAddAll( - vars, - keyPrefix+"/"+objkey, - objvalue.(map[string]interface{})) - } - } -} - func (c *Client) WatchPrefix(prefix string, keys []string, waitIndex uint64, stopChan chan bool) (uint64, error) { <-stopChan return 0, nil diff --git a/config.go b/config.go index 8fa987113..5e7caa5ac 100644 --- a/config.go +++ b/config.go @@ -50,7 +50,6 @@ var ( appID string userID string yamlFile string - filePath string ) // A Config structure is used to configure confd. @@ -79,7 +78,6 @@ type Config struct { AppID string `toml:"app_id"` UserID string `toml:"user_id"` YAMLFile string `toml:"file"` - FilePath string `toml:"file_path"` } func init() { @@ -111,7 +109,6 @@ func init() { flag.StringVar(&username, "username", "", "the username to authenticate as (only used with vault and etcd backends)") flag.StringVar(&password, "password", "", "the password to authenticate with (only used with vault and etcd backends)") flag.BoolVar(&watch, "watch", false, "enable watch support") - flag.StringVar(&filePath, "file", "", "file containing data") } // initConfig initializes the confd configuration by first setting defaults, @@ -163,7 +160,7 @@ func initConfig() error { } // Update BackendNodes from SRV records. - if config.Backend != "env" && config.Backend != "json" && config.SRVRecord != "" { + if config.Backend != "env" && config.SRVRecord != "" { log.Info("SRV record set to " + config.SRVRecord) srvNodes, err := getBackendNodesFromSRV(config.SRVRecord, config.Scheme) if err != nil { @@ -228,7 +225,6 @@ func initConfig() error { AppID: config.AppID, UserID: config.UserID, YAMLFile: config.YAMLFile, - FilePath: config.FilePath, } // Template configuration. templateConfig = template.Config{ @@ -330,9 +326,7 @@ func setConfigFromFlag(f *flag.Flag) { config.AppID = appID case "user-id": config.UserID = userID - case "yaml": - config.YAMLFile = yamlFile case "file": - config.FilePath = filePath + config.YAMLFile = yamlFile } } diff --git a/integration/json/sample.json b/integration/json/sample.json deleted file mode 100644 index 6e887f5bf..000000000 --- a/integration/json/sample.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "key": "foobar", - "database": - { - "host": "127.0.0.1", - "password": "p@sSw0rd", - "port": "3306", - "username": "confd" - }, - "upstream": - { - "app1": "10.0.1.10:8080", - "app2": "10.0.1.11:8080" - }, - "prefix": - { - "database": - { - "host": "127.0.0.1", - "password": "p@sSw0rd", - "port": "3306", - "username": "confd" - }, - "upstream": - { - "app1": "10.0.1.10:8080", - "app2": "10.0.1.11:8080" - } - } -} diff --git a/integration/json/test.sh b/integration/json/test.sh deleted file mode 100755 index 351234878..000000000 --- a/integration/json/test.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -e - -# Run confd -confd --onetime --log-level debug \ - --confdir ./integration/confdir \ - --backend json \ - --file ./integration/json/sample.json