Created
October 1, 2025 17:40
-
-
Save AndrewDryga/0006ee9aa18597702cebe59a41de69f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script enables WebSockets on all of your pullzones. To use it you need to set your API key like so: | |
# | |
# export BUNNY_API_KEY="" | |
# | |
#!/usr/bin/env bash | |
# enable websockets on all BunnyCDN Pull Zones, then verify | |
set -euo pipefail | |
: "${BUNNY_API_KEY:?export BUNNY_API_KEY=...}" | |
BASE="https://api.bunny.net" | |
LIST_URL="$BASE/pullzone?page=0&perPage=1000&includeCertificate=false" | |
echo "Listing zones, enabling WebSockets where needed…" | |
curl -sS -H "AccessKey: $BUNNY_API_KEY" -H "Accept: application/json" "$LIST_URL" \ | |
| jq -r ' | |
def items: | |
if type=="array" then . | |
else (.Items // .items // []) | |
end; | |
items[] | |
| [(.Id // .id), (.Name // .name), ((.EnableWebSockets // .enableWebSockets // false) | tostring)] | |
| @tsv | |
' \ | |
| while IFS=$'\t' read -r id name enabled; do | |
if [[ "$enabled" != "true" ]]; then | |
echo " -> $name ($id): enabling" | |
curl -sS -X POST \ | |
-H "AccessKey: $BUNNY_API_KEY" \ | |
-H "Accept: application/json" \ | |
-H "Content-Type: application/json" \ | |
-d '{"EnableWebSockets": true}' \ | |
"$BASE/pullzone/$id" >/dev/null | |
else | |
echo " -> $name ($id): already enabled" | |
fi | |
done | |
echo | |
echo "Verifying all zones now have EnableWebSockets=true…" | |
curl -sS -H "AccessKey: $BUNNY_API_KEY" -H "Accept: application/json" "$LIST_URL" \ | |
| jq -r ' | |
def items: | |
if type=="array" then . | |
else (.Items // .items // []) | |
end; | |
items[] | |
| select((.EnableWebSockets // .enableWebSockets // false) != true) | |
| "\((.Id // .id))\t\((.Name // .name))\tws=\((.EnableWebSockets // .enableWebSockets))" | |
' \ | |
| { out=$(cat); if [[ -n "$out" ]]; then echo "These zones still not enabled:"; echo "$out"; exit 2; else echo "All good ✅"; fi; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment