new add_to_zone function which is more dnspythonic, add DNAME records
This commit is contained in:
parent
2fa0aece48
commit
d8d67379e0
1 changed files with 23 additions and 17 deletions
40
lib.py
40
lib.py
|
@ -34,7 +34,7 @@ def format_rname(mail: str):
|
|||
return rname
|
||||
|
||||
|
||||
def format_mname(name: str):
|
||||
def format_re2o_domain(name: str):
|
||||
"""
|
||||
Format a zone name given by the re2o API to a mname dnspython object.
|
||||
|
||||
|
@ -51,29 +51,17 @@ def format_mname(name: str):
|
|||
|
||||
return mname
|
||||
|
||||
#def add_to_zone(zone, name, rdata):
|
||||
# """Add a rdata object to a zone object."""
|
||||
#
|
||||
# zone.nodes.setdefault(name, dns.node.Node())
|
||||
# rdataset = zone.nodes[name].find_rdataset(
|
||||
# rdata.rdclass,
|
||||
# rdata.rdtype,
|
||||
# create=True
|
||||
# )
|
||||
# rdataset.add(rdata)
|
||||
|
||||
|
||||
def add_to_zone(zone, name, rdata):
|
||||
"""Add a rdata object to a zone object."""
|
||||
|
||||
rdataset = zone.find_rdataset(
|
||||
name,
|
||||
node = zone.find_node(name, create=True)
|
||||
rdataset = node.find_rdataset(
|
||||
rdata.rdclass,
|
||||
rdata.rdtype,
|
||||
create=True
|
||||
)
|
||||
rdataset.add(rdata)
|
||||
|
||||
|
||||
def soa_handler(re2o_zone, dns_zone):
|
||||
"""Handler for SOA record"""
|
||||
|
||||
|
@ -307,6 +295,24 @@ def cname_records_handler(re2o_zone, dns_zone):
|
|||
|
||||
add_to_zone(dns_zone, name, CNAME_obj)
|
||||
|
||||
def dname_records_handler(re2o_zone, dns_zone):
|
||||
"""Handler for DNAME records"""
|
||||
|
||||
for record in re2o_zone["dname_records"]:
|
||||
|
||||
logging.debug(f"DNAME = {record}")
|
||||
|
||||
alias = format_re2o_domain(record["alias"])
|
||||
zone = format_re2o_domain(record["zone"])
|
||||
|
||||
DNAME_obj = DNAME.DNAME(
|
||||
dns.rdataclass.IN,
|
||||
dns.rdatatype.DNAME,
|
||||
alias
|
||||
)
|
||||
|
||||
add_to_zone(dns_zone, zone, DNAME_obj)
|
||||
|
||||
|
||||
def pass_handler(zone, records):
|
||||
pass
|
||||
|
@ -323,7 +329,7 @@ HANDLERS = {
|
|||
"srv_records": srv_records_handler,
|
||||
"a_records": a_records_handler,
|
||||
"aaaa_records": aaaa_records_handler,
|
||||
"name": pass_handler,
|
||||
"cname_records": cname_records_handler,
|
||||
"dname_records": pass_handler,
|
||||
"name": pass_handler,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue