5

I need to get all the consul kv values using http api. Currently I can get the one value with the following command.

curl -k -X GET https://consul.banuka1.us-east-2.test:8543/v1/kv/banuka-test/test-value?token=1995-08-18

it returns only the value specified in it (test-value)

But I want to get all the values in the kv store

How can I do this? Is there a workaround here?

NOTE: I have already done this using consul cli but I want to do this with https api

Jananath Banuka
  • 493
  • 3
  • 11
  • 22

2 Answers2

13

You can simplify this and reduce the number of API calls by using the recurse=true query argument.

curl http://127.0.0.1:8500/v1/kv/\?recurse=true | jq -r '.[].Value | @base64d' 
Blake Covarrubias
  • 2,138
  • 2
  • 6
  • 14
6

I usually do this to print all the keys and values.

v1/kv/?keys - returns all the keys

I then iterate each key and read the raw response and decode the base64 value.

while read -r key
do    
    value=`curl --silent "http://127.0.0.1:8500/v1/kv/$key" | jq -r '.[].Value' | base64 --decode`
    echo "$key - $value"
done < <(curl --silent "http://127.0.0.1:8500/v1/kv/?keys"| jq -r '.[]')
Amjad Hussain Syed
  • 994
  • 2
  • 11
  • 23