Skip to content

Commit 7a64d52

Browse files
authored
Merge pull request #26 from mittwald/kv-key
Do not escape kv key names to support nested keys
2 parents 8285c03 + 1744762 commit 7a64d52

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

kv_v1.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package vault
22

3-
import (
4-
"net/url"
5-
)
6-
73
const (
84
pathPrefix string = "v1"
95
)
@@ -30,7 +26,7 @@ func (k *KVv1) Create(id string, data map[string]string) error {
3026
[]string{
3127
pathPrefix,
3228
k.MountPoint,
33-
url.PathEscape(id),
29+
id,
3430
}, data, nil, nil,
3531
)
3632
if err != nil {
@@ -51,7 +47,7 @@ func (k *KVv1) Read(key string) (*KVv1ReadResponse, error) {
5147
[]string{
5248
pathPrefix,
5349
k.MountPoint,
54-
url.PathEscape(key),
50+
key,
5551
}, readRes, nil,
5652
)
5753
if err != nil {
@@ -74,7 +70,7 @@ func (k *KVv1) List(key string) (*KVv1ListResponse, error) {
7470
[]string{
7571
pathPrefix,
7672
k.MountPoint,
77-
url.PathEscape(key),
73+
key,
7874
}, nil, listRes, nil,
7975
)
8076
if err != nil {
@@ -89,7 +85,7 @@ func (k *KVv1) Delete(key string) error {
8985
[]string{
9086
pathPrefix,
9187
k.MountPoint,
92-
url.PathEscape(key),
88+
key,
9389
}, nil, nil, nil,
9490
)
9591
if err != nil {

kv_v1_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,19 @@ func (s *KVv1TestSuite) TestCreateAndList() {
8686

8787
require.NoError(s.T(), s.client.Create("foo", testKeyValues))
8888
require.NoError(s.T(), s.client.Create("foo2", testKeyValues))
89+
require.NoError(s.T(), s.client.Create("foo3/test", testKeyValues))
8990

9091
list, listErr := s.client.List("")
9192
require.NoError(s.T(), listErr)
9293

9394
require.Contains(s.T(), list.Data.Keys, "foo")
9495
require.Contains(s.T(), list.Data.Keys, "foo2")
95-
require.Len(s.T(), list.Data.Keys, 2)
96+
require.Contains(s.T(), list.Data.Keys, "foo3/")
97+
require.Len(s.T(), list.Data.Keys, 3)
9698

99+
nestedList, nestedListErr := s.client.List("foo3")
100+
require.NoError(s.T(), nestedListErr)
101+
102+
require.Contains(s.T(), nestedList.Data.Keys, "test")
103+
require.Len(s.T(), nestedList.Data.Keys, 1)
97104
}

0 commit comments

Comments
 (0)