mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-24 03:30:50 +02:00
Formatting for nameservers
This commit is contained in:
parent
1644109292
commit
18447c1486
2 changed files with 40 additions and 2 deletions
|
@ -2,6 +2,7 @@ from itertools import zip_longest
|
|||
import logging
|
||||
import ipaddress
|
||||
import re
|
||||
import string
|
||||
from datetime import date
|
||||
from string import digits
|
||||
from typing import Optional
|
||||
|
@ -228,6 +229,43 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@Cache
|
||||
def format_nameservers(self):
|
||||
"""
|
||||
Formatting nameservers for display for this domain.
|
||||
|
||||
Hosts are provided as a list of tuples, e.g.
|
||||
|
||||
[("ns1.example.com",), ("ns1.example.gov", ["0.0.0.0"])]
|
||||
|
||||
We want to display as:
|
||||
ns1.example.gov
|
||||
ns1.example.gov (0.0.0.0)
|
||||
|
||||
Subordinate hosts (something.your-domain.gov) MUST have IP addresses,
|
||||
while non-subordinate hosts MUST NOT.
|
||||
|
||||
|
||||
"""
|
||||
try:
|
||||
hosts = self._get_property("hosts")
|
||||
except Exception as err:
|
||||
# Do not raise error when missing nameservers
|
||||
# this is a standard occurence when a domain
|
||||
# is first created
|
||||
logger.info("Domain is missing nameservers %s" % err)
|
||||
return []
|
||||
|
||||
hostList = []
|
||||
for host in hosts:
|
||||
host_info = host["name"]
|
||||
if len(host["addrs"]) > 0:
|
||||
converter = string.maketrans("[]", "()")
|
||||
host_info.append(host["addrs"].translate(converter, "'"))
|
||||
hostList.append(host_info)
|
||||
|
||||
return hostList
|
||||
|
||||
@Cache
|
||||
def nameservers(self) -> list[tuple[str, list]]:
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue