-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Use the facade class to make route53 calls and output to actions
- Loading branch information
1 parent
62c85b1
commit d468aee
Showing
1 changed file
with
19 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |