Skip to content

Commit

Permalink
Merge pull request #24 from mittwald/kv-list
Browse files Browse the repository at this point in the history
Implement List for KV v1
  • Loading branch information
git-flexi authored Jun 5, 2024
2 parents 4c22830 + 57a9177 commit 62b111d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
23 changes: 23 additions & 0 deletions kv_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ func (k *KVv1) Read(key string) (*KVv1ReadResponse, error) {
return readRes, nil
}

type KVv1ListResponse struct {
Data struct {
Keys []string `json:"keys"`
} `json:"data"`
}

func (k *KVv1) List(key string) (*KVv1ListResponse, error) {
listRes := &KVv1ListResponse{}

err := k.client.List(
[]string{
pathPrefix,
k.MountPoint,
url.PathEscape(key),
}, nil, listRes, nil,
)
if err != nil {
return nil, err
}

return listRes, nil
}

func (k *KVv1) Delete(key string) error {
err := k.client.Delete(
[]string{
Expand Down
16 changes: 16 additions & 0 deletions kv_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,19 @@ func (s *KVv1TestSuite) TestCreateAndDelete() {
_, readErr := s.client.Read("2b7ff26d-30b7-43ba-96d5-79b4baba9b39")
require.Error(s.T(), readErr)
}

func (s *KVv1TestSuite) TestCreateAndList() {
testKeyValues := make(map[string]string)
testKeyValues["PrivateKey"] = "abcde"

require.NoError(s.T(), s.client.Create("foo", testKeyValues))
require.NoError(s.T(), s.client.Create("foo2", 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)

}

0 comments on commit 62b111d

Please sign in to comment.