-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·63 lines (55 loc) · 1.59 KB
/
test.sh
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
#!/bin/bash
if [ -f .env ]; then
source .env
else
echo ".env file not found!"
exit 1
fi
echo $REALM
read_token(){
username="$1"
response=$(curl -s -X POST "${OIDC_SERVER_URL}/realms/${REALM}/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=${CLIENT_ID}" \
-d "client_secret=${CLIENT_SECRET}" \
-d "username=${username}" \
-d "password=${PASSWORD}" \
-d "grant_type=password")
echo $response | jq -r .access_token
}
read_service(){
local access_token="$1"
local service_path="$2"
if [ "$service_path" != "/do" ]; then
echo "Trying GET http://localhost:8000${service_path}"
curl -s -X GET "http://localhost:8000${service_path}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $access_token" | jq
fi
echo ""
echo "Trying POST http://localhost:8000${service_path}"
curl -s -X POST "http://localhost:8000${service_path}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $access_token" | jq
}
read -p "Is it a secured service? (y/n): " IS_SECURED
if [ "$IS_SECURED" == "y" ]; then
read -p "Enter your username: " USERNAME
access_token=$(read_token "$USERNAME")
echo "Got token!"
if [ "$access_token" == "null" ]; then
echo "Failed to get access token"
exit 1
fi
else
access_token="NA"
fi
while true; do
echo ""
read -p "Enter the service path, e.g. '/a' (RETURN to stop): " SERVICE_PATH
if [ -n "$SERVICE_PATH" ]; then
read_service "$access_token" "$SERVICE_PATH"
else
break
fi
done