Skip to content

Commit

Permalink
♻️ Use the Facade class and improve some logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonBirchall committed Jun 28, 2024
1 parent 98d4d50 commit 4cecbd3
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions check_empty_zones.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
import sys

import boto3


def get_aws_zones():
route53 = boto3.client("route53")
zones = []
paginator = route53.get_paginator("list_hosted_zones")
for page in paginator.paginate():
for zone in page["HostedZones"]:
zones.append((zone["Id"], zone["Name"]))
return zones


def is_zone_empty(zone_id):
route53 = boto3.client("route53")
paginator = route53.get_paginator("list_resource_record_sets")
for page in paginator.paginate(HostedZoneId=zone_id):
for record_set in page["ResourceRecordSets"]:
# Ignore NS and SOA records as they are default
if record_set["Type"] not in ["NS", "SOA"]:
return False
return True
from providers.route53 import Route53Facade


def main():
print("Checking for empty hosted zones...")
client = Route53Facade()
zones = client.get_aws_zones()

empty_zones = []
for zone_id, zone_name in get_aws_zones():
if is_zone_empty(zone_id):
# Remove trailing dot from zone name
empty_zones.append(zone_name.rstrip("."))
for zone_id, zone in zones:
if client.is_zone_empty(zone_id):
empty_zones.append(zone.rstrip("."))

if empty_zones:
print("The following hosted zones are empty:")
Expand Down

0 comments on commit 4cecbd3

Please sign in to comment.