From 51f3b7dde0ff14eebc4d06d8eb09d6fcccd53a2d Mon Sep 17 00:00:00 2001 From: Kush Bavishi Date: Mon, 22 Jul 2019 14:23:40 -0700 Subject: [PATCH] Added the Record class for UltraDNS --- lemur/plugins/lemur_acme/ultradns.py | 10 +++++--- lemur/plugins/lemur_acme/ultradns_record.py | 26 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 lemur/plugins/lemur_acme/ultradns_record.py diff --git a/lemur/plugins/lemur_acme/ultradns.py b/lemur/plugins/lemur_acme/ultradns.py index eb595789..95adc77a 100644 --- a/lemur/plugins/lemur_acme/ultradns.py +++ b/lemur/plugins/lemur_acme/ultradns.py @@ -2,6 +2,7 @@ import time import requests import json from .ultradns_zone import Zone +from .ultradns_record import Record import dns import dns.exception @@ -223,13 +224,15 @@ def delete_txt_record(change_id, account_number, domain, token): try: rrsets = _get(path) + record = Record(rrsets) except Exception as e: metrics.send("delete_txt_record_geterror", "counter", 1) # No Text Records remain or host is not in the zone anymore because all records have been deleted. return try: # Remove the record from the RRSet locally - rrsets["rrSets"][0]["rdata"].remove("{}".format(token)) + # rrsets["rrSets"][0]["rdata"].remove("{}".format(token)) + record.rdata.remove("{}".format(token)) except ValueError: current_app.logger.debug("Token not found") return @@ -238,10 +241,11 @@ def delete_txt_record(change_id, account_number, domain, token): _delete(path) # Check if the RRSet has more records. If yes, add the modified RRSet back to UltraDNS - if len(rrsets["rrSets"][0]["rdata"]) > 0: + # if len(rrsets["rrSets"][0]["rdata"]) > 0: + if len(record.rdata) > 0: params = { "ttl": 300, - "rdata": rrsets["rrSets"][0]["rdata"], + "rdata": record.rdata, } _post(path, params) diff --git a/lemur/plugins/lemur_acme/ultradns_record.py b/lemur/plugins/lemur_acme/ultradns_record.py new file mode 100644 index 00000000..9ec8d4d8 --- /dev/null +++ b/lemur/plugins/lemur_acme/ultradns_record.py @@ -0,0 +1,26 @@ +class Record: + """ + This class implements an Ultra DNS record. + Accepts the response from the API call as the argument. + """ + + def __init__(self, _data): + # Since we are dealing with only TXT records for Lemur, we expect only 1 RRSet in the response. + # Thus we default to picking up the first entry (_data["rrsets"][0]) from the response. + self._data = _data["rrSets"][0] + + @property + def name(self): + return self._data["ownerName"] + + @property + def rrtype(self): + return self._data["rrtype"] + + @property + def rdata(self): + return self._data["rdata"] + + @property + def ttl(self): + return self._data["ttl"]