Update logic for making sure we clear out ip address field

This commit is contained in:
Rebecca Hsieh 2024-02-16 12:01:44 -08:00
parent 00434d3461
commit 448fc6ed16
No known key found for this signature in database

View file

@ -427,7 +427,6 @@ class Domain(TimeStampedModel, DomainHelper):
raise NameserverError(code=nsErrorCodes.INVALID_HOST, nameserver=nameserver) raise NameserverError(code=nsErrorCodes.INVALID_HOST, nameserver=nameserver)
elif cls.isSubdomain(name, nameserver) and (ip is None or ip == []): elif cls.isSubdomain(name, nameserver) and (ip is None or ip == []):
raise NameserverError(code=nsErrorCodes.MISSING_IP, nameserver=nameserver) raise NameserverError(code=nsErrorCodes.MISSING_IP, nameserver=nameserver)
elif not cls.isSubdomain(name, nameserver) and (ip is not None and ip != []): elif not cls.isSubdomain(name, nameserver) and (ip is not None and ip != []):
raise NameserverError(code=nsErrorCodes.GLUE_RECORD_NOT_ALLOWED, nameserver=nameserver, ip=ip) raise NameserverError(code=nsErrorCodes.GLUE_RECORD_NOT_ALLOWED, nameserver=nameserver, ip=ip)
elif ip is not None and ip != []: elif ip is not None and ip != []:
@ -1778,6 +1777,10 @@ class Domain(TimeStampedModel, DomainHelper):
for cleaned_host in cleaned_hosts: for cleaned_host in cleaned_hosts:
# Check if the cleaned_host already exists # Check if the cleaned_host already exists
host_in_db, host_created = Host.objects.get_or_create(domain=self, name=cleaned_host["name"]) host_in_db, host_created = Host.objects.get_or_create(domain=self, name=cleaned_host["name"])
# Check if the nameserver is a subdomain of the current domain
# If it is NOT a subdomain, we remove the IP address
if not Domain.isSubdomain(self.name, cleaned_host["name"]):
cleaned_host["addrs"] = [] # or None
# Get cleaned list of ips for update # Get cleaned list of ips for update
cleaned_ips = cleaned_host["addrs"] cleaned_ips = cleaned_host["addrs"]
if not host_created: if not host_created: