Added error handling if key is not in A or AAAA

This commit is contained in:
Firq 2022-11-27 18:03:11 +01:00
parent fedae40fc4
commit 6a059e6806
Signed by: Firq
GPG key ID: 4DE1059A4666E89F

View file

@ -31,7 +31,16 @@ def main():
for dnsrecord in dns_records:
if ipversion == 'skipping':
print(f"DNS Name: {dnsrecord['name']} | ID: {dnsrecord['id']} | Type : {dnsrecord['type']} | IP: {dnsrecord['content']}")
dns_names[dnsrecord['type']].append(dnsrecord["name"])
if dnsrecord['type'] in ['A', 'AAAA']:
dns_names[dnsrecord['type']].append(dnsrecord["name"])
else:
print(f"Cannot resolve record {dnsrecord['name']} because of type {dnsrecord['type']}")
print(f"------ Full DNS record ------\n"
f"{dnsrecord}"
f"\n---------------------------"
)
with open('cloudflare.json', 'r') as file:
values = json.load(file)
@ -55,7 +64,7 @@ def main():
if fullname in dns_names['A']:
new_dnsrecords = {"name": fullname, "type": "A", "content": ip_address_new}
print(f"Sending request {new_dnsrecords}")
r = cf.zones.dns_records.put(zone_id, dns_record_id, data=new_dnsrecords)
r = cf.zones.dns_records.patch(zone_id, dns_record_id, data=new_dnsrecords)
print(r)
case '6':
@ -75,7 +84,7 @@ def main():
if fullname in dns_names['AAAA']:
new_dnsrecords = {"name": fullname, "type": "AAAA", "content": ip_address_new}
print(f"Sending request {new_dnsrecords}")
r = cf.zones.dns_records.put(zone_id, dns_record_id, data=new_dnsrecords)
r = cf.zones.dns_records.patch(zone_id, dns_record_id, data=new_dnsrecords)
print(r)
case 'skipping':
print("Done")