-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkong-api-release.sh
65 lines (56 loc) · 1.38 KB
/
kong-api-release.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
61
62
63
64
65
#!/bin/bash
option="$1"
usage() {
echo "Usage: $0 [option]"
echo "Options:"
echo " -release : api release from kong to repository"
echo " -deploy : api deploy from repository to kong"
exit 1
}
folder_exists() {
local dir_name="$1"
for n in "${names[@]}"; do
if [ "$dir_name" == "$n" ]; then
return 0
fi
done
return 1
}
handle_api_release() {
response=$(curl -s -X GET "http://0.0.0.0:8001/services")
names=($(echo "$response" | jq -r '.data[].name'))
for dir in */; do
dir_name="${dir%/}"
if ! folder_exists "$dir_name"; then
rm -rf "$dir_name"
echo "Deleted API \"$dir_name\"."
fi
done
for name in "${names[@]}"; do
if [ -d "$name" ]; then
json_data=$(echo "$response" | jq -r --arg n "$name" '.data[] | select(.name == $n)')
echo "$json_data" > "$name/api-content.json"
echo "API Content \"$name\" updated."
else
mkdir -p "$name"
json_data=$(echo "$response" | jq -r --arg n "$name" '.data[] | select(.name == $n)')
echo "$json_data" > "$name/api-content.json"
echo "API Folder \"$name\" created."
fi
done
}
handle_api_deploy() {
./var/lib/jenkins/kong/kong-api-deployment.sh
}
main() {
if [ -z "$option" ]; then
usage
elif [ "$option" = "-release" ]; then
handle_api_release
elif [ "$option" = "-deploy" ]; then
handle_api_deploy
else
usage
fi
}
main