Files
dyolink/infrastructure/scripts/arvan-dns-cleanup.py

29 lines
845 B
Python
Executable File

#!/usr/bin/env python3
"""Remove the _acme-challenge TXT record created for one Certbot attempt."""
import os
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from arvan_dns import delete_record, list_txt, record_names_match, txt_text, zone_and_record
def main():
domain = os.environ["CERTBOT_DOMAIN"]
value = os.environ.get("CERTBOT_VALIDATION", "")
zone, name, fqdn = zone_and_record(domain)
for record in list_txt(zone):
if str(record.get("type", "")).lower() != "txt":
continue
if not record_names_match(record.get("name"), name, fqdn):
continue
if value and value not in txt_text(record):
continue
delete_record(zone, record["id"])
print("TXT record removed")
if __name__ == "__main__":
main()