Skip to content

Instantly share code, notes, and snippets.

@rtldg
Created May 16, 2023 22:31
Show Gist options
  • Save rtldg/00a89d23d547ee39e6f4d9687911f7df to your computer and use it in GitHub Desktop.
Save rtldg/00a89d23d547ee39e6f4d9687911f7df to your computer and use it in GitHub Desktop.
purge old cloudflare pages deployments
# SPDX-License-Identifier: WTFPL
# pip install cloudflare
# Create token with Account -- Cloudflare Pages:Edit, Workers Scripts:Edit
# CLOUDFLARE_API_TOKEN="secret" python purge.py
import CloudFlare
cf = CloudFlare.CloudFlare()
zones = cf.zones.get()
accounts = cf.accounts.get()
for account in accounts:
projects = cf.accounts.pages.projects.get(account["id"])
for project in projects:
deployments = cf.accounts.pages.projects.deployments.get(account["id"], project["name"])[3:]
for deployment in deployments:
print(f'deleting {account["id"]} - {project["name"]} - {deployment["id"]}')
cf.accounts.pages.projects.deployments.delete(account["id"], project["name"], deployment["id"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment