-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudflare-cache-purger
More file actions
executable file
·41 lines (32 loc) · 1 KB
/
cloudflare-cache-purger
File metadata and controls
executable file
·41 lines (32 loc) · 1 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
#!/bin/sh
# https://api.cloudflare.com/#zone-purge-files-by-url
abort() { # Prints the message in red to stderr
printf "\033[31m ABORTED: $1\n\033[0m" >&2
exit 1
}
# brew install dialog
# sudo pacman -S dialog
command -v dialog > /dev/null || abort "Please install dialog"
ZONE_ID=enter-the-zone-id-for-example-com # example.com
TOKEN=enter-the-token # Permissions: Zone | Cache Purge | Purge
API="https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache"
PAGES="
example.com
example.com/page-a
"
checkboxes=""
for page in $PAGES; do
checkboxes="$checkboxes $page off"
done
chosen=$(dialog --stdout --no-lines --no-items --checklist "Purge" 0 0 0 $checkboxes)
test "$chosen" || abort "Please select a resource"
# Join URLs with commas
urls=""
for page in $chosen; do
urls="${urls}, \"https://${page}\""
done
urls=$(echo "$urls" | sed "s/^,//") # Remove the leading comma
curl -X POST $API \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
--data "{ \"files\": [$urls] }"