Created
May 16, 2023 22:31
-
-
Save rtldg/00a89d23d547ee39e6f4d9687911f7df to your computer and use it in GitHub Desktop.
purge old cloudflare pages deployments
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
# 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