-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-curl.sh
More file actions
executable file
·58 lines (52 loc) · 1.36 KB
/
Copy pathadmin-curl.sh
File metadata and controls
executable file
·58 lines (52 loc) · 1.36 KB
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
#!/usr/bin/env bash
# Examples for talking to the kroxy admin RPC.
#
# The admin RPC is JSON-RPC 2.0 over HTTP. By default kroxy binds it to
# 127.0.0.1:9095. The compose stack publishes it on host port 19095.
#
# Override the endpoint with $ADMIN to point at a different host/port:
# ADMIN=http://localhost:19095/rpc ./examples/admin-curl.sh list
#
# kroxy is a SASL/PLAIN pass-through: the SASL username on the wire is
# the tenant ID, and the password is forwarded verbatim to the upstream
# Kafka cluster, which is the auth authority. kroxy itself stores no
# secrets.
set -euo pipefail
ADMIN="${ADMIN:-http://127.0.0.1:9095/rpc}"
usage() {
cat <<EOF
Usage: $0 <command> [args]
Commands:
list
set <id> <topic_prefix> <upstream>
delete <id>
EOF
exit 2
}
call() {
local method="$1" params="$2"
curl -sS -X POST "$ADMIN" \
-H 'Content-Type: application/json' \
--data "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"$method\",\"params\":$params}" \
| jq .
}
cmd="${1:-}"; shift || true
case "$cmd" in
list)
call "Tenants.List" '{}'
;;
set)
[ "$#" -eq 3 ] || usage
id="$1" prefix="$2" upstream="$3"
call "Tenants.Set" \
"{\"id\":\"$id\",\"topic_prefix\":\"$prefix\",\"upstream\":\"$upstream\"}"
;;
delete)
[ "$#" -eq 1 ] || usage
id="$1"
call "Tenants.Delete" "{\"id\":\"$id\"}"
;;
*)
usage
;;
esac