Name uniformisation trying to follow standards
This commit is contained in:
parent
c935fa152a
commit
f9c54af626
1 changed files with 23 additions and 20 deletions
43
lib.py
43
lib.py
|
@ -48,9 +48,9 @@ def format_re2o_domain(name: str):
|
||||||
if name[0] == ".":
|
if name[0] == ".":
|
||||||
name = name[1:]
|
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):
|
def add_to_zone(zone, name, rdata):
|
||||||
"""Add a rdata object to a zone object."""
|
"""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
|
# DNS Name object for Hostname
|
||||||
hostname = record["hostname"]
|
hostname = record["hostname"]
|
||||||
key_name = dns.name.Name(hostname)
|
name_obj = dns.name.Name(hostname)
|
||||||
|
|
||||||
for fp in record["sshfp"]:
|
for fp in record["sshfp"]:
|
||||||
logging.debug(f"SSHFP = {fp}")
|
logging.debug(f"SSHFP = {fp}")
|
||||||
|
@ -199,7 +199,7 @@ def sshfp_record_handler(re2o_zone, dns_zone):
|
||||||
fingerprint,
|
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):
|
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
|
# DNS Name object for field1
|
||||||
name = record["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(
|
TXT_obj = TXT.TXT(
|
||||||
dns.rdataclass.IN,
|
dns.rdataclass.IN,
|
||||||
|
@ -241,7 +244,7 @@ def txt_records_handler(re2o_zone, dns_zone):
|
||||||
record["field2"]
|
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):
|
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}")
|
logging.debug(f"SRV = {record}")
|
||||||
|
|
||||||
# DNS Name obj for SRV
|
# 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(
|
SRV_obj = SRV.SRV(
|
||||||
dns.rdataclass.IN,
|
dns.rdataclass.IN,
|
||||||
|
@ -263,7 +266,7 @@ def srv_records_handler(re2o_zone, dns_zone):
|
||||||
record["target"]
|
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):
|
def a_records_handler(re2o_zone, dns_zone):
|
||||||
"""Handler for A Record"""
|
"""Handler for A Record"""
|
||||||
|
@ -274,7 +277,7 @@ def a_records_handler(re2o_zone, dns_zone):
|
||||||
|
|
||||||
# DNS Name object for Hostname
|
# DNS Name object for Hostname
|
||||||
hostname = record["hostname"]
|
hostname = record["hostname"]
|
||||||
key_name = dns.name.Name((hostname,))
|
name_obj = dns.name.Name((hostname,))
|
||||||
|
|
||||||
ipv4_addr = record["ipv4"]
|
ipv4_addr = record["ipv4"]
|
||||||
|
|
||||||
|
@ -284,7 +287,7 @@ def a_records_handler(re2o_zone, dns_zone):
|
||||||
ipv4_addr
|
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):
|
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
|
# DNS Name object for Hostname
|
||||||
hostname = record["hostname"]
|
hostname = record["hostname"]
|
||||||
key_name = dns.name.Name((hostname,))
|
name_obj = dns.name.Name((hostname,))
|
||||||
|
|
||||||
ipv6_addr = record["ipv6"][0]["ipv6"] # thanks re2o
|
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):
|
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}")
|
logging.debug(f"CNAME = {record}")
|
||||||
|
|
||||||
target = dns.name.from_text(record["alias"])
|
alias_obj = dns.name.from_text(record["alias"])
|
||||||
name = dns.name.from_text(record["hostname"], origin=None)
|
name_obj = dns.name.from_text(record["hostname"], origin=None)
|
||||||
|
|
||||||
CNAME_obj = CNAME.CNAME(
|
CNAME_obj = CNAME.CNAME(
|
||||||
dns.rdataclass.IN,
|
dns.rdataclass.IN,
|
||||||
dns.rdatatype.CNAME,
|
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):
|
def dname_records_handler(re2o_zone, dns_zone):
|
||||||
"""Handler for DNAME records"""
|
"""Handler for DNAME records"""
|
||||||
|
@ -339,16 +342,16 @@ def dname_records_handler(re2o_zone, dns_zone):
|
||||||
|
|
||||||
logging.debug(f"DNAME = {record}")
|
logging.debug(f"DNAME = {record}")
|
||||||
|
|
||||||
alias = format_re2o_domain(record["alias"])
|
name_obj = format_re2o_domain(record["alias"])
|
||||||
zone = format_re2o_domain(record["zone"])
|
target_obj = format_re2o_domain(record["zone"])
|
||||||
|
|
||||||
DNAME_obj = DNAME.DNAME(
|
DNAME_obj = DNAME.DNAME(
|
||||||
dns.rdataclass.IN,
|
dns.rdataclass.IN,
|
||||||
dns.rdatatype.DNAME,
|
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):
|
def pass_handler(zone, records):
|
||||||
|
|
Loading…
Reference in a new issue