From 70649247a341a80e0145e188544ca44b8ed9b231 Mon Sep 17 00:00:00 2001 From: "Dr. Kyle Morton" Date: Thu, 15 Sep 2022 17:57:59 -0500 Subject: [PATCH] fix: Updated logic to process vault response for GetKeys (#162) * fix: Updated logic to process vault response for GetKeys Signed-off-by: Kyle Morton --- internal/pkg/vault/secrets.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/pkg/vault/secrets.go b/internal/pkg/vault/secrets.go index 326e8586..cd4ff6cf 100644 --- a/internal/pkg/vault/secrets.go +++ b/internal/pkg/vault/secrets.go @@ -487,8 +487,9 @@ func (c *Client) getAllPaths(subPath string) ([]string, error) { resp, err := c.HttpCaller.Do(req) if err != nil { - return nil, err + return nil, fmt.Errorf("unable to get all paths: %v", err) } + defer func() { _ = resp.Body.Close() }() @@ -501,18 +502,16 @@ func (c *Client) getAllPaths(subPath string) ([]string, error) { return nil, pkg.NewErrSecretStore(fmt.Sprintf("Received a '%d' response from the secret store", resp.StatusCode)) } - var result map[string]map[string][]interface{} - err = json.NewDecoder(resp.Body).Decode(&result) + // Structure of the json data returned. + data := struct { + Data map[string][]string `json:"data"` + }{} + + err = json.NewDecoder(resp.Body).Decode(&data) if err != nil { return nil, err } - data := result["data"]["keys"] - // Cast the keys to strings - var secretKeys []string - for _, v := range data { - secretKeys = append(secretKeys, v.(string)) - } - + secretKeys := data.Data["keys"] return secretKeys, nil }