-
Notifications
You must be signed in to change notification settings - Fork 3
/
clean_records.py
65 lines (52 loc) · 1.84 KB
/
clean_records.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Install the Python Requests library:
# `pip install requests`
import os
import requests
AUTH_API_TOKEN = os.environ["HETZNERDNS_TOKEN"]
print(AUTH_API_TOKEN)
def list_records(ZoneID):
# Get Records
# GET https://dns.hetzner.com/api/v1/records
try:
response = requests.get(
url="https://dns.hetzner.com/api/v1/records",
params={
"zone_id": ZoneID,
},
headers={
"Auth-API-Token": AUTH_API_TOKEN,
},
)
print('Response HTTP Status Code: {status_code}'.format(
status_code=response.status_code))
print('Response HTTP Response Body: {content}'.format(
content=response.content))
except requests.exceptions.RequestException:
print('HTTP Request failed')
return response.json()
def delete_record(RecordID):
# Delete Record
# DELETE https://dns.hetzner.com/api/v1/records/{RecordID}
try:
response = requests.delete(
url=f"https://dns.hetzner.com/api/v1/records/{RecordID}",
headers={
"Auth-API-Token": AUTH_API_TOKEN,
},
)
print('Response HTTP Status Code: {status_code}'.format(
status_code=response.status_code))
print('Response HTTP Response Body: {content}'.format(
content=response.content))
except requests.exceptions.RequestException:
print('HTTP Request failed')
records = list_records("bambi.ovh")["records"]
print(records)
for record in records:
print("RECORD", record["name"], "->", record["value"])
#delete_record(record['id'])
confirm = input("Enter \"yes\" to delete all records")
if confirm.strip() == "yes":
for record in records:
print("DETLETING RECORD", record["name"], "->", record["value"])
delete_record(record['id'])