Skip to content

Instantly share code, notes, and snippets.

@progrium
Created June 4, 2014 22:21
Show Gist options
  • Save progrium/b45a9fe697dd68c3ea0f to your computer and use it in GitHub Desktop.
Save progrium/b45a9fe697dd68c3ea0f to your computer and use it in GitHub Desktop.
Consul KV client, depends on jq
#!/bin/bash
CONSUL="localhost:8500"
main() {
case "$1" in
info)
curl -s "$CONSUL/v1/kv/$2" | jq -r .[]
;;
get)
curl -s "$CONSUL/v1/kv/$2" | jq -r .[].Value | base64 -d | sed 's/$/\n/'
;;
set)
curl -s -X PUT -d "$3" "$CONSUL/v1/kv/$2" > /dev/null
;;
del)
curl -s -X DELETE -d "$3" "$CONSUL/v1/kv/$2" > /dev/null
;;
ls)
if [[ "$2" == "" ]]; then
curl -s "$CONSUL/v1/kv/?keys" | jq -r .[]
else
curl -s "$CONSUL/v1/kv/$2/?keys" | jq -r .[] | sed "s|$2/||"
fi
;;
esac
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment