This commit is contained in:
+9
-2
@@ -16,8 +16,10 @@ except ImportError:
|
||||
|
||||
load_dotenv()
|
||||
|
||||
log_level = os.getenv("LOG_LEVEL", "INFO").upper()
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
level=log_level,
|
||||
format="%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
)
|
||||
@@ -45,14 +47,18 @@ def _get_current_record(hosted_zone_id: str, record: str, record_type: str) -> s
|
||||
if rrset["Name"].rstrip(".") == record_normalized and rrset["Type"] == record_type:
|
||||
records = rrset.get("ResourceRecords", [])
|
||||
if records:
|
||||
return records[0]["Value"].rstrip(".")
|
||||
value = records[0]["Value"].rstrip(".")
|
||||
logger.debug("Found %s record %s: value='%s' (len=%d)", record_type, record, value, len(value))
|
||||
return value
|
||||
except Exception as e:
|
||||
logger.warning("Failed to get current %s record for %s: %s", record_type, record, e)
|
||||
logger.debug("No %s record found for %s", record_type, record)
|
||||
return None
|
||||
|
||||
|
||||
def update_ipv4(hosted_zone_id: str, record: str, public_ipv4: str) -> bool:
|
||||
current = _get_current_record(hosted_zone_id, record, "A")
|
||||
logger.debug("IPv4 comparison for %s: current='%s' (len=%d) vs desired='%s' (len=%d)", record, current, len(current or ""), public_ipv4, len(public_ipv4))
|
||||
if current == public_ipv4:
|
||||
logger.info("IPv4 for %s is already %s, no update needed", record, public_ipv4)
|
||||
return False
|
||||
@@ -87,6 +93,7 @@ def update_ipv4(hosted_zone_id: str, record: str, public_ipv4: str) -> bool:
|
||||
|
||||
def update_ipv6(hosted_zone_id: str, record: str, public_ipv6: str) -> bool:
|
||||
current = _get_current_record(hosted_zone_id, record, "AAAA")
|
||||
logger.debug("IPv6 comparison for %s: current='%s' (len=%d) vs desired='%s' (len=%d)", record, current, len(current or ""), public_ipv6, len(public_ipv6))
|
||||
if current == public_ipv6:
|
||||
logger.info("IPv6 for %s is already %s, no update needed", record, public_ipv6)
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user