-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·53 lines (46 loc) · 2.06 KB
/
entrypoint.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
#!/bin/bash
set -o pipefail
# Create /root/.edgerc file from env variable
echo -e "${EDGERC}" > ~/.edgerc
# Set Variables
zoneName=$1
# update zone using HTTPie and https://developer.akamai.com/api/cloud_security/edge_dns_zone_management/v2.html#postchangelistrecordsets
# check if zone file exists
if [ -f ${zoneName}.zone ] ; then
echo "Zone file exists: ${zoneName}.zone"
else
echo -e "Error: ${zoneName}.zone is missing.\nYou may want to add a file called ${zoneName}.zone into the repository with the contents similar to the one below:\n"
mycommand0="http --print=b -A edgegrid -a dns: GET :/config-dns/v2/zones/${zoneName}/zone-file Accept:text/dns | grep -v \;\;"
eval $mycommand0 > output0
cat output0
exit 123
fi
# response=$(http edgeworkers list-ids --json --section edgeworkers --edgerc ~/.edgerc)
echo "1. uploading zone file"
mycommand1="cat ${zoneName}.zone | http --print=HhbB -A edgegrid -a dns: POST :/config-dns/v2/zones/${zoneName}/zone-file Content-Type:text/dns"
echo "Running: $mycommand1"
eval $mycommand1 > output1
status=$(cat output1 | grep 'HTTP/1.1 ' | awk '{print $2}')
if [ $status -eq 204 ] ; then
# Extract eTag value
versionID=$(cat output1 | grep 'ETag:' | sed 's/"//g' | awk '{print $2}')
echo -e "Zone file accepted!\nZone version: ${versionID}\n"
else
echo -e "Error: Status code=${status} (expected 204)\nAPI response:"
tail -1 output1 | jq .
exit 123
fi
# Check status of new version
echo "2. Checking activation status"
mycommand2="http --print=HhbB -A edgegrid -a dns: GET :/config-dns/v2/zones/${zoneName}/versions/${versionID}"
echo "Running: $mycommand2"
eval $mycommand2 > output2
status=$(tail -1 output2 | jq -r .activationState)
apibody=$(tail -1 output2 | jq .)
echo -e "API response:\n${apibody}"
if [ $status = "PENDING" ] ; then
# do something like send a slack message indicating zone started activating, activation ETA is around 5min
echo "Zone is activating (most activations take less than 5 minutes to complete)"
# don't loop to check if version is active to avoid consuming GitHub runner minutes
exit 0
fi