-
-
Save kenichi-shibata/2e978c56c9dd6b2806ba5df6e59759ad to your computer and use it in GitHub Desktop.
Executes cURL to purge the cache on Cloudflare for a specified set or all files (requires config)
This file contains 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
#!/bin/sh | |
# Author: Pat Migliaccio <[email protected]> | |
# License: MIT | |
EMAIL="<Acct_Email>" | |
ZONE="<Zone_ID>" | |
API_KEY="<API_Key>" | |
DATA="{ \"files\": [\"https://example.com/css/style.css\"] }" | |
# Purges all files with `-a` or `--all` flags | |
if [[ "$1" == "--all" || "$1" == "-a" ]]; then | |
echo "Purging everything..." | |
config[data]="{ \"purge_everything\": true }" | |
elif [ ! -z "$1" ]; then | |
echo "Command not found: $1" | |
exit 1 | |
fi | |
# Calls Cloudflare API to Purge Files | |
# Reference: https://api.cloudflare.com/#zone-purge-files-by-url | |
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE/purge_cache" \ | |
-H "X-Auth-Email: $EMAIL" \ | |
-H "X-Auth-Key: $API_KEY" \ | |
-H "Content-Type: application/json" \ | |
--data "$DATA" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment