mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 12:08:40 +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 logging
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import re
|
import re
|
||||||
|
import string
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from string import digits
|
from string import digits
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
@ -228,6 +229,43 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
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
|
@Cache
|
||||||
def nameservers(self) -> list[tuple[str, list]]:
|
def nameservers(self) -> list[tuple[str, list]]:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
{% url 'domain-dns-nameservers' pk=domain.id as url %}
|
{% url 'domain-dns-nameservers' pk=domain.id as url %}
|
||||||
{% if domain.nameservers|length > 0 %}
|
{% if domain.format_nameservers|length > 0 %}
|
||||||
{% include "includes/summary_item.html" with title='DNS name servers' value=domain.nameservers list='true' edit_link=url %}
|
{% include "includes/summary_item.html" with title='DNS name servers' value=domain.format_nameservers list='true' edit_link=url %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<h2 class="margin-top-neg-1"> DNS name servers </h2>
|
<h2 class="margin-top-neg-1"> DNS name servers </h2>
|
||||||
<p> No DNS name servers have been added yet. Before your domain can be used we’ll need information about your domain name servers.</p>
|
<p> No DNS name servers have been added yet. Before your domain can be used we’ll need information about your domain name servers.</p>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue