Skip to content

Commit

Permalink
Use forward slash to separate section/key in config fetching
Browse files Browse the repository at this point in the history
To ensure future compatibility, since keys may contain periods at some time,
but will never contain slashes, as URL compatibility is required.
  • Loading branch information
flimzy committed Apr 24, 2021
1 parent 918c27f commit 905a7ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/kouchctl/cmd/get_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func getConfigCmd(r *root) *cobra.Command {

pf := cmd.PersistentFlags()
pf.StringVarP(&c.node, "node", "n", "_local", "Specify the node name to query")
pf.StringVarP(&c.key, "key", "k", "", "Fetch only the specified config section, and optionally key, separated by a period")
pf.StringVarP(&c.key, "key", "k", "", "Fetch only the specified config section, and optionally key, separated by a slash")

return cmd
}
Expand All @@ -48,7 +48,7 @@ func configFromDSN(dsn *url.URL) (node, key string, ok bool) {
if len(parts) < 4 || parts[1] != "_node" || parts[3] != "_config" {
return "", "", false
}
return parts[2], strings.Join(parts[4:], "."), true
return parts[2], strings.Join(parts[4:], "/"), true
}

func (c *getConfig) RunE(cmd *cobra.Command, _ []string) error {
Expand All @@ -70,7 +70,7 @@ func (c *getConfig) RunE(cmd *cobra.Command, _ []string) error {
var conf interface{}
var err error
if c.key != "" {
if parts := strings.SplitN(c.key, ".", 2); len(parts) > 1 {
if parts := strings.SplitN(c.key, "/", 2); len(parts) > 1 {
conf, err = client.ConfigValue(cmd.Context(), c.node, parts[0], parts[1])
} else {
conf, err = client.ConfigSection(cmd.Context(), c.node, c.key)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kouchctl/cmd/get_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func Test_get_config_RunE(t *testing.T) {
})

return cmdTest{
args: []string{"get", "config", s.URL, "--key", "chttpd.backlog"},
args: []string{"get", "config", s.URL, "--key", "chttpd/backlog"},
}
})

Expand Down Expand Up @@ -125,7 +125,7 @@ func Test_configFromDSN(t *testing.T) {
tests.Add("config key", tt{
dsn: "http://foo.com/_node/foo/_config/foo/bar",
node: "foo",
key: "foo.bar",
key: "foo/bar",
ok: true,
})

Expand Down

0 comments on commit 905a7ce

Please sign in to comment.