Skip to content

Commit

Permalink
✨ Use the facade class to make route53 calls and output to actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonBirchall committed Jun 28, 2024
1 parent 62c85b1 commit d468aee
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions check_unmanaged_zones.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
import os
import sys

import boto3
from providers.route53 import Route53Facade


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["Name"].rstrip(".")) # Remove trailing dot
return set(zones)


def get_config_zones():
def get_config_zones() -> list:
zones_dir = "hostedzones"
config_zones = []
for filename in os.listdir(zones_dir):
if filename.endswith(".yaml"):
config_zones.append(filename[:-5]) # Remove .yaml extension
return set(config_zones)
return config_zones


def github_actions_output(output, exit_code):
print(output)
os.environ["GITHUB_OUTPUT"] = output
sys.exit(exit_code)


def main():
aws_zones = get_aws_zones()
client = Route53Facade()
aws_zones = [zone[1] for zone in client.get_aws_zones()]
config_zones = get_config_zones()

unmanaged_zones = aws_zones - config_zones

unmanaged_zones = set(aws_zones) - set(config_zones)
if unmanaged_zones:
print("The following zones exist in AWS but are not managed by octoDNS:")
for zone in sorted(unmanaged_zones):
print(f" - {zone}")
sys.exit(1)
output = "The following zones exist in AWS but are not managed by octoDNS:\n"
output += "\n".join(f" - {zone}" for zone in sorted(unmanaged_zones))
return output, 1
else:
print("All AWS Route53 zones are managed by octoDNS.")
sys.exit(0)
output = "All AWS Route53 zones are managed by octoDNS."
return output, 0


if __name__ == "__main__":
main()
output, exit_code = main()
github_actions_output(output, exit_code)

0 comments on commit d468aee

Please sign in to comment.