some minor modifications

This commit is contained in:
David Kennedy 2023-12-29 16:05:00 -05:00
parent d0ca1ccff1
commit 66bc63aad4
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B

View file

@ -1608,7 +1608,8 @@ class Domain(TimeStampedModel, DomainHelper):
cache = self._extract_data_from_response(data_response)
cleaned = self._clean_cache(cache, data_response)
self._update_hosts_and_contacts(cleaned, fetch_hosts, fetch_contacts)
self._update_hosts_and_ips_in_db(cleaned, fetch_hosts)
if fetch_hosts:
self._update_hosts_and_ips_in_db(cleaned)
self._update_dates(cleaned)
self._cache = cleaned
@ -1655,7 +1656,11 @@ class Domain(TimeStampedModel, DomainHelper):
return dnssec_data
def _update_hosts_and_contacts(self, cleaned, fetch_hosts, fetch_contacts):
"""Capture and cache old hosts and contacts from cache if they don't exist in cleaned"""
"""
Update hosts and contacts if fetch_hosts and/or fetch_contacts.
Additionally, capture and cache old hosts and contacts from cache if they
don't exist in cleaned
"""
old_cache_hosts = self._cache.get("hosts")
old_cache_contacts = self._cache.get("contacts")
@ -1670,16 +1675,15 @@ class Domain(TimeStampedModel, DomainHelper):
if old_cache_contacts is not None:
cleaned["contacts"] = old_cache_contacts
def _update_hosts_and_ips_in_db(self, cleaned, fetch_hosts):
def _update_hosts_and_ips_in_db(self, cleaned):
"""Update hosts and host_ips in database if retrieved from registry.
Only called when fetch_hosts is True.
Parameters:
self: the domain to be updated with hosts and ips from cleaned
cleaned: dict containing hosts. Hosts are provided as a list of dicts, e.g.
[{"name": "ns1.example.com",}, {"name": "ns1.example.gov"}, "addrs": ["0.0.0.0"])]
fetch_hosts: boolean indicating whether or not fetch_hosts was called
"""
if fetch_hosts:
cleaned_hosts = cleaned["hosts"]
# Get all existing hosts from the database for this domain
existing_hosts_in_db = Host.objects.filter(domain=self)