Skip to content

Commit

Permalink
Revert "json-backend: tests and support for nested objects"
Browse files Browse the repository at this point in the history
This reverts commit efce8ea.
  • Loading branch information
Matthew Fisher committed Oct 27, 2016
1 parent 0df8af7 commit c91406c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 85 deletions.
41 changes: 2 additions & 39 deletions backends/json/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package json
import (
"encoding/json"
"io/ioutil"
"strings"
)

// Client provides a shell for the json client
Expand All @@ -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
}
Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ var (
appID string
userID string
yamlFile string
filePath string
)

// A Config structure is used to configure confd.
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -228,7 +225,6 @@ func initConfig() error {
AppID: config.AppID,
UserID: config.UserID,
YAMLFile: config.YAMLFile,
FilePath: config.FilePath,
}
// Template configuration.
templateConfig = template.Config{
Expand Down Expand Up @@ -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
}
}
30 changes: 0 additions & 30 deletions integration/json/sample.json

This file was deleted.

8 changes: 0 additions & 8 deletions integration/json/test.sh

This file was deleted.

0 comments on commit c91406c

Please sign in to comment.