Name uniformisation trying to follow standards

This commit is contained in:
otthorn 2021-04-15 01:38:46 +02:00
parent c935fa152a
commit f9c54af626

43
lib.py
View file

@ -48,9 +48,9 @@ def format_re2o_domain(name: str):
if name[0] == ".":
name = name[1:]
mname = dns.name.from_text(name)
name_obj = dns.name.from_text(name)
return mname
return name_obj
def add_to_zone(zone, name, rdata):
"""Add a rdata object to a zone object."""
@ -180,7 +180,7 @@ def sshfp_record_handler(re2o_zone, dns_zone):
# DNS Name object for Hostname
hostname = record["hostname"]
key_name = dns.name.Name(hostname)
name_obj = dns.name.Name(hostname)
for fp in record["sshfp"]:
logging.debug(f"SSHFP = {fp}")
@ -199,7 +199,7 @@ def sshfp_record_handler(re2o_zone, dns_zone):
fingerprint,
)
add_to_zone(dns_zone, key_name, SSHFP_obj)
add_to_zone(dns_zone, name_obj, SSHFP_obj)
def mx_records_handler(re2o_zone, dns_zone):
@ -233,7 +233,10 @@ def txt_records_handler(re2o_zone, dns_zone):
# DNS Name object for field1
name = record["field1"]
key_name = dns.name.Name((name,))
if name == "@":
name_obj = AT
else:
name_obj = format_re2o_domain(name)
TXT_obj = TXT.TXT(
dns.rdataclass.IN,
@ -241,7 +244,7 @@ def txt_records_handler(re2o_zone, dns_zone):
record["field2"]
)
add_to_zone(dns_zone, key_name, TXT_obj)
add_to_zone(dns_zone, name_obj, TXT_obj)
def srv_records_handler(re2o_zone, dns_zone):
@ -252,7 +255,7 @@ def srv_records_handler(re2o_zone, dns_zone):
logging.debug(f"SRV = {record}")
# DNS Name obj for SRV
key_name = dns.name.from_text(f"{record['service']}_{record['protocol']}")
name_ovj = dns.name.from_text(f"{record['service']}_{record['protocol']}")
SRV_obj = SRV.SRV(
dns.rdataclass.IN,
@ -263,7 +266,7 @@ def srv_records_handler(re2o_zone, dns_zone):
record["target"]
)
add_to_zone(dns_zone, key_name, SRV_obj)
add_to_zone(dns_zone, name_obj, SRV_obj)
def a_records_handler(re2o_zone, dns_zone):
"""Handler for A Record"""
@ -274,7 +277,7 @@ def a_records_handler(re2o_zone, dns_zone):
# DNS Name object for Hostname
hostname = record["hostname"]
key_name = dns.name.Name((hostname,))
name_obj = dns.name.Name((hostname,))
ipv4_addr = record["ipv4"]
@ -284,7 +287,7 @@ def a_records_handler(re2o_zone, dns_zone):
ipv4_addr
)
add_to_zone(dns_zone, key_name, A_obj)
add_to_zone(dns_zone, name_obj, A_obj)
def aaaa_records_handler(re2o_zone, dns_zone):
@ -300,7 +303,7 @@ def aaaa_records_handler(re2o_zone, dns_zone):
# DNS Name object for Hostname
hostname = record["hostname"]
key_name = dns.name.Name((hostname,))
name_obj = dns.name.Name((hostname,))
ipv6_addr = record["ipv6"][0]["ipv6"] # thanks re2o
@ -311,7 +314,7 @@ def aaaa_records_handler(re2o_zone, dns_zone):
)
add_to_zone(dns_zone, key_name, AAAA_obj)
add_to_zone(dns_zone, name_obj, AAAA_obj)
def cname_records_handler(re2o_zone, dns_zone):
@ -321,16 +324,16 @@ def cname_records_handler(re2o_zone, dns_zone):
logging.debug(f"CNAME = {record}")
target = dns.name.from_text(record["alias"])
name = dns.name.from_text(record["hostname"], origin=None)
alias_obj = dns.name.from_text(record["alias"])
name_obj = dns.name.from_text(record["hostname"], origin=None)
CNAME_obj = CNAME.CNAME(
dns.rdataclass.IN,
dns.rdatatype.CNAME,
target
alias_obj
)
add_to_zone(dns_zone, name, CNAME_obj)
add_to_zone(dns_zone, name_obj, CNAME_obj)
def dname_records_handler(re2o_zone, dns_zone):
"""Handler for DNAME records"""
@ -339,16 +342,16 @@ def dname_records_handler(re2o_zone, dns_zone):
logging.debug(f"DNAME = {record}")
alias = format_re2o_domain(record["alias"])
zone = format_re2o_domain(record["zone"])
name_obj = format_re2o_domain(record["alias"])
target_obj = format_re2o_domain(record["zone"])
DNAME_obj = DNAME.DNAME(
dns.rdataclass.IN,
dns.rdatatype.DNAME,
zone
target_obj
)
add_to_zone(dns_zone, alias, DNAME_obj)
add_to_zone(dns_zone, name_obj, DNAME_obj)
def pass_handler(zone, records):