This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconsulkv
61 lines (56 loc) · 1.79 KB
/
consulkv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# Borrowed from: https://gist.github.com/progrium/b45a9fe697dd68c3ea0f
# All credit to @progrium.
if [ -f /etc/default/octohost ]; then
. /etc/default/octohost
else
CONSUL_SERVER="localhost:8500"
fi
# Adding anonymous token by default.
if [ -z $CONSUL_TOKEN ];
then
CONSUL_TOKEN="anonymous"
fi
main() {
case "$1" in
info)
curl -s "$CONSUL_SERVER/v1/kv/$2?token=$CONSUL_TOKEN" | jq -r .[]
;;
get)
curl -s "$CONSUL_SERVER/v1/kv/$2?token=$CONSUL_TOKEN" | jq -r .[].Value | base64 -d
;;
set)
curl -s -X PUT -d "$3" "$CONSUL_SERVER/v1/kv/$2?token=$CONSUL_TOKEN" > /dev/null
;;
del)
curl -s -X DELETE -d "$3" "$CONSUL_SERVER/v1/kv/$2?token=$CONSUL_TOKEN" > /dev/null
;;
ls)
if [[ "$2" == "" ]]; then
curl -s "$CONSUL_SERVER/v1/kv/?keys&token=$CONSUL_TOKEN" | jq -r .[]
else
curl -s "$CONSUL_SERVER/v1/kv/$2/?keys&token=$CONSUL_TOKEN" | jq -r .[] | sed "s|$2/||"
fi
;;
service:set)
curl -s -X PUT -d "$2" "$CONSUL_SERVER/v1/agent/service/register?token=$CONSUL_TOKEN"
;;
service:del)
curl -s "$CONSUL_SERVER/v1/agent/service/deregister/$2?token=$CONSUL_TOKEN"
;;
service:health)
STATUS=$(curl -s "$CONSUL_SERVER/v1/health/service/$2?token=$CONSUL_TOKEN" | jq '.[].Checks[0].Status' | cut -d '"' -f 2)
echo $STATUS
;;
services)
curl -s "$CONSUL_SERVER/v1/agent/services?token=$CONSUL_TOKEN" | jq -c '.[]'
;;
services:catalog)
for service in $( curl -s "$CONSUL_SERVER/v1/catalog/services?token=$CONSUL_TOKEN" | jq 'keys' | jq '.[]' ); do
SERVICE=$(echo $service | cut -d '"' -f 2)
curl -s "$CONSUL_SERVER/v1/catalog/service/$SERVICE?token=$CONSUL_TOKEN" | jq -c '.[]'
done
;;
esac
}
main "$@"