Skip to content

Commit 57a9177

Browse files
committed
Implement List for KV v1
1 parent 4c22830 commit 57a9177

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

kv_v1.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,29 @@ func (k *KVv1) Read(key string) (*KVv1ReadResponse, error) {
6161
return readRes, nil
6262
}
6363

64+
type KVv1ListResponse struct {
65+
Data struct {
66+
Keys []string `json:"keys"`
67+
} `json:"data"`
68+
}
69+
70+
func (k *KVv1) List(key string) (*KVv1ListResponse, error) {
71+
listRes := &KVv1ListResponse{}
72+
73+
err := k.client.List(
74+
[]string{
75+
pathPrefix,
76+
k.MountPoint,
77+
url.PathEscape(key),
78+
}, nil, listRes, nil,
79+
)
80+
if err != nil {
81+
return nil, err
82+
}
83+
84+
return listRes, nil
85+
}
86+
6487
func (k *KVv1) Delete(key string) error {
6588
err := k.client.Delete(
6689
[]string{

kv_v1_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,19 @@ func (s *KVv1TestSuite) TestCreateAndDelete() {
7979
_, readErr := s.client.Read("2b7ff26d-30b7-43ba-96d5-79b4baba9b39")
8080
require.Error(s.T(), readErr)
8181
}
82+
83+
func (s *KVv1TestSuite) TestCreateAndList() {
84+
testKeyValues := make(map[string]string)
85+
testKeyValues["PrivateKey"] = "abcde"
86+
87+
require.NoError(s.T(), s.client.Create("foo", testKeyValues))
88+
require.NoError(s.T(), s.client.Create("foo2", testKeyValues))
89+
90+
list, listErr := s.client.List("")
91+
require.NoError(s.T(), listErr)
92+
93+
require.Contains(s.T(), list.Data.Keys, "foo")
94+
require.Contains(s.T(), list.Data.Keys, "foo2")
95+
require.Len(s.T(), list.Data.Keys, 2)
96+
97+
}

0 commit comments

Comments
 (0)