Skip to content

Commit

Permalink
fix: Updated logic to process vault response for GetKeys (#162)
Browse files Browse the repository at this point in the history
* fix: Updated logic to process vault response for GetKeys

Signed-off-by: Kyle Morton <[email protected]>
  • Loading branch information
drkfmorton authored Sep 15, 2022
1 parent 46e806f commit 7064924
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions internal/pkg/vault/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}()
Expand All @@ -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
}

0 comments on commit 7064924

Please sign in to comment.