Created
November 14, 2023 04:25
-
-
Save nZac/6d60cafeb3afa13f70bb38b0eeb277a1 to your computer and use it in GitHub Desktop.
Simple validation script for Route 53 record-set JSON outputs
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
"""Simple validation script for Route 53 record-set JSON outputs | |
Only validates some record types | |
aws route53 list-resource-record-sets --hosted-zone-id zone-id-old > old-dns.json | |
aws route53 list-resource-record-sets --hosted-zone-id zone-id-new > new-dns.json | |
""" | |
from __future__ import annotations | |
import typing as t | |
import json | |
from dataclasses import dataclass | |
@dataclass | |
class Record: | |
name: str | |
type_: str | |
ttl: str | None | |
records: list[dict[str, str]] | |
@classmethod | |
def from_json(cls, data: dict[str, t.Any]) -> Record: | |
if "AliasTarget" in data: | |
raise NotImplementedError("no alias target") | |
return cls( | |
name=data["Name"], | |
type_=data["Type"], | |
ttl=data.get("TTL", None), | |
records=data["ResourceRecords"], | |
) | |
@classmethod | |
def from_record_sets_json(cls, path: str) -> list[Record]: | |
with open(path) as fp: | |
data = json.load(fp) | |
records: list[Record] = [] | |
for record in data["ResourceRecordSets"]: | |
try: | |
records.append(cls.from_json(record)) | |
except NotImplementedError: | |
continue | |
return records | |
old = Record.from_record_sets_json("old-dns.json") | |
new = Record.from_record_sets_json("new-dns.json") | |
missing_in_old: list[Record] = [] | |
for o in old: | |
if o not in new: | |
missing_in_old.append(o) | |
for x in missing_in_old: | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment