From db3a517e7a63a0f514f708bd79301533ccb1e3bd Mon Sep 17 00:00:00 2001 From: Mark van Holsteijn Date: Mon, 4 Jul 2022 14:50:39 +0200 Subject: [PATCH] check name for idna and unicode string --- src/zonefile_migrate/to_cloudformation.py | 13 ++++++------- src/zonefile_migrate/to_terraform.py | 3 ++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/zonefile_migrate/to_cloudformation.py b/src/zonefile_migrate/to_cloudformation.py index 9122430..96f837d 100644 --- a/src/zonefile_migrate/to_cloudformation.py +++ b/src/zonefile_migrate/to_cloudformation.py @@ -59,22 +59,21 @@ def convert_to_cloudformation(zone: easyzone.Zone, maximum_ttl: int) -> dict: """ ttl = zone.root.ttl domain_name = zone.domain + idna_domain_name = domain_name.encode("idna").decode("ascii") result = CommentedMap() result["AWSTemplateFormatVersion"] = "2010-09-09" resources = CommentedMap() resources["HostedZone"] = CommentedMap( - {"Type": "AWS::Route53::HostedZone", "Properties": {"Name": zone.domain.encode("idna").decode("ascii")}} + {"Type": "AWS::Route53::HostedZone", "Properties": {"Name": idna_domain_name}} ) result["Resources"] = resources for record_set in create_from_zone(zone): - if record_set.rectype == "NS" and record_set.name == zone.domain: - log.debug("ignoring NS records for origin %s", zone.domain) - continue - if record_set.rectype == "SOA": - log.debug("ignoring SOA records for domain %s", record_set.name) - continue + if record_set.name in [zone.domain, idna_domain_name]: + if record_set.rectype in ["NS", "SOA"]: + log.debug("ignoring %s records for origin %s", record_set.rectype, zone.domain) + continue logical_name = generate_unique_logical_resource_id( re.sub( diff --git a/src/zonefile_migrate/to_terraform.py b/src/zonefile_migrate/to_terraform.py index b41c77e..53e4109 100644 --- a/src/zonefile_migrate/to_terraform.py +++ b/src/zonefile_migrate/to_terraform.py @@ -40,11 +40,12 @@ def convert_to_terraform(zone: easyzone.Zone, provider: str, maximum_ttl: int) - Converts the zonefile into a terraform tempalte for Google """ domain_name = zone.domain + idna_domain_name = domain_name.encode("idna").decode("ascii") resource_name = re.sub(r"\.", "_", zone.domain.removesuffix(".")) resource_record_sets = list( filter( lambda r: not ( - r.rectype == "SOA" or (r.rectype == "NS" and r.name == zone.domain) + r.rectype in ["SOA", "NS"] and r.name in [domain_name, idna_domain_name] ), create_from_zone(zone), )