updating _get_txt_records return values and docstrings
This commit is contained in:
parent
6f3ba23fa0
commit
f82ec24dfa
|
@ -202,7 +202,11 @@ def delete_txt_record(change_id, account_number, domain, token):
|
||||||
"token": token,
|
"token": token,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Determine if we can delete whole RRset or just one record
|
"""
|
||||||
|
Get existing TXT records matching the domain from DNS
|
||||||
|
The token to be deleted should already exist
|
||||||
|
There may be other records with different tokens as well
|
||||||
|
"""
|
||||||
cur_records = _get_txt_records(domain)
|
cur_records = _get_txt_records(domain)
|
||||||
found = False
|
found = False
|
||||||
new_records = []
|
new_records = []
|
||||||
|
@ -212,12 +216,16 @@ def delete_txt_record(change_id, account_number, domain, token):
|
||||||
else:
|
else:
|
||||||
new_records.append(record)
|
new_records.append(record)
|
||||||
|
|
||||||
if not found: # Record not found in DNS
|
# Since the matching token is not in DNS, there is nothing to delete
|
||||||
log_data["message"] = "Unable to delete TXT record: TXT record not found"
|
if not found:
|
||||||
|
log_data["message"] = "Unable to delete TXT record: Token not found in existing TXT records"
|
||||||
current_app.logger.debug(log_data)
|
current_app.logger.debug(log_data)
|
||||||
return
|
return
|
||||||
|
|
||||||
elif new_records: # Removing Record from RRSet via Patch
|
# The record to delete has been found AND there are other tokens set on the same domain
|
||||||
|
# Since we only want to delete one token value from the RRSet, we need to use the Patch command to
|
||||||
|
# overwrite the current RRSet with the existing records.
|
||||||
|
elif new_records:
|
||||||
try:
|
try:
|
||||||
_patch_txt_records(domain, account_number, new_records)
|
_patch_txt_records(domain, account_number, new_records)
|
||||||
log_data["message"] = "TXT record successfully deleted"
|
log_data["message"] = "TXT record successfully deleted"
|
||||||
|
@ -228,7 +236,9 @@ def delete_txt_record(change_id, account_number, domain, token):
|
||||||
log_data["message"] = "Unable to delete TXT record: patching exception"
|
log_data["message"] = "Unable to delete TXT record: patching exception"
|
||||||
current_app.logger.debug(log_data)
|
current_app.logger.debug(log_data)
|
||||||
|
|
||||||
else: # Delete current records
|
# The record to delete has been found AND there are no other token values set on the same domain
|
||||||
|
# Use the Delete command to delete the whole RRSet.
|
||||||
|
else:
|
||||||
zone_name = _get_zone_name(domain, account_number)
|
zone_name = _get_zone_name(domain, account_number)
|
||||||
server_id = current_app.config.get("ACME_POWERDNS_SERVERID", "localhost")
|
server_id = current_app.config.get("ACME_POWERDNS_SERVERID", "localhost")
|
||||||
zone_id = zone_name + "."
|
zone_id = zone_name + "."
|
||||||
|
@ -319,7 +329,6 @@ def _get_txt_records(domain):
|
||||||
Retrieve TXT records for a given domain and return list of Record Objects
|
Retrieve TXT records for a given domain and return list of Record Objects
|
||||||
|
|
||||||
:param domain: FQDN
|
:param domain: FQDN
|
||||||
:raise: Exception
|
|
||||||
:return: list of Record objects
|
:return: list of Record objects
|
||||||
"""
|
"""
|
||||||
server_id = current_app.config.get("ACME_POWERDNS_SERVERID", "localhost")
|
server_id = current_app.config.get("ACME_POWERDNS_SERVERID", "localhost")
|
||||||
|
@ -336,9 +345,10 @@ def _get_txt_records(domain):
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sentry.captureException()
|
sentry.captureException()
|
||||||
|
log_data["Exception"] = e
|
||||||
log_data["message"] = "Failed to Retrieve TXT Records"
|
log_data["message"] = "Failed to Retrieve TXT Records"
|
||||||
current_app.logger.debug(log_data)
|
current_app.logger.debug(log_data)
|
||||||
raise
|
return []
|
||||||
|
|
||||||
txt_records = []
|
txt_records = []
|
||||||
for record in records:
|
for record in records:
|
||||||
|
|
|
@ -165,7 +165,7 @@ class TestPowerdns(unittest.TestCase):
|
||||||
"function": "delete_txt_record",
|
"function": "delete_txt_record",
|
||||||
"fqdn": domain,
|
"fqdn": domain,
|
||||||
"token": token,
|
"token": token,
|
||||||
"message": "Unable to delete TXT record: TXT record not found"
|
"message": "Unable to delete TXT record: Token not found in existing TXT records"
|
||||||
}
|
}
|
||||||
powerdns.delete_txt_record(change_id, account_number, domain, token)
|
powerdns.delete_txt_record(change_id, account_number, domain, token)
|
||||||
mock_current_app.logger.debug.assert_called_with(log_data)
|
mock_current_app.logger.debug.assert_called_with(log_data)
|
||||||
|
|
Loading…
Reference in New Issue