-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.tftpl
77 lines (66 loc) · 2.37 KB
/
configure.tftpl
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
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
set -x
set -e
start_time=$(date +%s)
cookie_file=$(mktemp)
response_file=$(mktemp)
function exit_on_timeout() {
now=$(date +%s)
elapsed=$((now-start_time))
if [ $elapsed -gt ${timeout} ]; then
echo "Timeout reached."
exit 1
fi
}
http_code=$(curl -k -s --cookie-jar $cookie_file -o $response_file -w "%%{http_code}" \
--request POST 'https://${mx_address}:8083/SecureSphere/api/v1/auth/session' \
--header "Authorization: Basic ${https_auth_header}")
if [ $http_code -ne 200 ]; then
echo "Failed to authenticate. http_code: $http_code."
exit 1
fi
trap "echo Running trap:; curl -k -s --cookie $cookie_file --request DELETE https://${mx_address}:8083/SecureSphere/api/v1/auth/session; rm -f $cookie_file $response_file" EXIT
echo "Waiting for first ADC content update:"
while true; do
http_code=$(curl -k -s --cookie $cookie_file -o $response_file -w "%%{http_code}" \
--request GET 'https://${mx_address}:8083/SecureSphere/api/v1/administration/adc/timestamp')
if [ "$http_code" -eq 200 ]; then
if ! grep '"adcTimestamp" *: *0' $response_file; then
echo "ADC content update is complete."
cat $response_file
break
fi
fi
exit_on_timeout
echo "sleep 1m"
sleep 60
done
%{ for config_value in configuration_elements }
echo "Setting ${config_value.name}:"
while true; do
url='${config_value.url_path}'
url=$${url// /%20} # encode uel spaces as %20
http_code=$(curl -k -s --cookie $cookie_file -o $response_file -w "%%{http_code}" \
--request ${config_value.method} 'https://${mx_address}:8083/'$url \
--header 'Content-Type: application/json' \
--data-raw '${config_value.payload}')
if [ "$http_code" -eq 200 ]; then
echo "Done with ${config_value.name}:"
break
fi
if [ "$http_code" -eq 406 ]; then
if grep 'IMP-10005\|IMP-10128\|IMP-13212' $response_file; then
# resource already exists
echo "Done with ${config_value.name}:"
break
fi
fi
exit_on_timeout
echo "sleep 1m"
sleep 60
done
%{ endfor ~}
# {"errors":[{"description":"System is busy. Please try again later.","error-code":"IMP-10001"}]}
# {"errors":[{"description":"Server Group not found","error-code":"IMP-10008"}]}
# {"errors":[{"description":"System is busy. Please try again later.","error-code":"IMP-10001"}]}
# {"errors":[{"description":"The \"db-service-type\" entered is illegal","error-code":"IMP-10016"}]}