Skip to content

Commit

Permalink
check name for idna and unicode string
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanholsteijn committed Jul 4, 2022
1 parent 0b6cafa commit db3a517
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/zonefile_migrate/to_cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/zonefile_migrate/to_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down

0 comments on commit db3a517

Please sign in to comment.