Skip to content

Commit

Permalink
Merge pull request #26 from mittwald/kv-key
Browse files Browse the repository at this point in the history
Do not escape kv key names to support nested keys
  • Loading branch information
git-flexi authored Jun 12, 2024
2 parents 8285c03 + 1744762 commit 7a64d52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 4 additions & 8 deletions kv_v1.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package vault

import (
"net/url"
)

const (
pathPrefix string = "v1"
)
Expand All @@ -30,7 +26,7 @@ func (k *KVv1) Create(id string, data map[string]string) error {
[]string{
pathPrefix,
k.MountPoint,
url.PathEscape(id),
id,
}, data, nil, nil,
)
if err != nil {
Expand All @@ -51,7 +47,7 @@ func (k *KVv1) Read(key string) (*KVv1ReadResponse, error) {
[]string{
pathPrefix,
k.MountPoint,
url.PathEscape(key),
key,
}, readRes, nil,
)
if err != nil {
Expand All @@ -74,7 +70,7 @@ func (k *KVv1) List(key string) (*KVv1ListResponse, error) {
[]string{
pathPrefix,
k.MountPoint,
url.PathEscape(key),
key,
}, nil, listRes, nil,
)
if err != nil {
Expand All @@ -89,7 +85,7 @@ func (k *KVv1) Delete(key string) error {
[]string{
pathPrefix,
k.MountPoint,
url.PathEscape(key),
key,
}, nil, nil, nil,
)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion kv_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,19 @@ func (s *KVv1TestSuite) TestCreateAndList() {

require.NoError(s.T(), s.client.Create("foo", testKeyValues))
require.NoError(s.T(), s.client.Create("foo2", testKeyValues))
require.NoError(s.T(), s.client.Create("foo3/test", testKeyValues))

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

require.Contains(s.T(), list.Data.Keys, "foo")
require.Contains(s.T(), list.Data.Keys, "foo2")
require.Len(s.T(), list.Data.Keys, 2)
require.Contains(s.T(), list.Data.Keys, "foo3/")
require.Len(s.T(), list.Data.Keys, 3)

nestedList, nestedListErr := s.client.List("foo3")
require.NoError(s.T(), nestedListErr)

require.Contains(s.T(), nestedList.Data.Keys, "test")
require.Len(s.T(), nestedList.Data.Keys, 1)
}

0 comments on commit 7a64d52

Please sign in to comment.