Skip to content

Commit e8fa4e1

Browse files
author
Griko Nibras
committed
feat(scripts): add purge-dns-records.py
1 parent 5214dc2 commit e8fa4e1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

scripts/purge-dns-records.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import requests
3+
4+
# https://dash.cloudflare.com/4b8a0a194b32a8d44b27cbe8e188174d/subjs.in
5+
zoneid = os.environ("ZONE_ID")
6+
7+
# https://dash.cloudflare.com/profile/api-tokens
8+
bearer_token = os.environ("BEARER_TOKEN")
9+
10+
if input("Are you sure you want to delete ALL DNS records in this zone? (y/n)") != "y":
11+
exit()
12+
13+
14+
# Fetch dns records from CloudFlare
15+
record_rq = requests.get(
16+
"https://api.cloudflare.com/client/v4/zones/" + zoneid + "/dns_records",
17+
headers={
18+
"Content-Type": "application/json",
19+
"Authorization": "Bearer " + bearer_token,
20+
},
21+
)
22+
data = record_rq.json()
23+
if data["success"] == False:
24+
print("Failed to fetch dns record:")
25+
print(data["errors"])
26+
quit()
27+
28+
# Delete dns records
29+
for record in data["result"]:
30+
print("Deleting:", record["name"])
31+
rq = requests.delete(
32+
"https://api.cloudflare.com/client/v4/zones/"
33+
+ zoneid
34+
+ "/dns_records/"
35+
+ record["id"],
36+
headers={
37+
"Content-Type": "application/json",
38+
"Authorization": "Bearer " + bearer_token,
39+
},
40+
)
41+
print(rq.status_code, "\n")

0 commit comments

Comments
 (0)