Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Apr 26, 2023
1 parent 027d3dc commit f66cb0d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions code/ddns-lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
LOGGER = logging.getLogger()
account_id = None
region = None
VERSION = '1.2.0b61'
VERSION = '1.2.0b63'

# Read Env variables
DEBUG_LOG_LEVEL = os.environ.get('DebugLogLevel', 'INFO')
Expand Down Expand Up @@ -403,14 +403,11 @@ def lambda_handler(
instance = get_item_from_dynamodb_table(dynamodb_client, DDBNAME, instance_id)
LOGGER.info("instance attributes: %s", str(instance) + lineno())
try:
# LOGGER.info(f"instance_data type {type(instance)} {lineno()}")
# instance_data = json.loads(instance)
# LOGGER.info(f"getting _DnsEntries {lineno()}")
dns_data_raw = instance.get('_DnsEntries', [])
LOGGER.info(
LOGGER.debug(
f"got _DnsEntries type {type(dns_data_raw)} value {dns_data_raw} {lineno()}")
dns_data = [dns_data_tuple(**item) for item in dns_data_raw]
LOGGER.info(f"converted _DnsEntries to namdtuples {dns_data} {lineno()}")
LOGGER.debug(f"converted _DnsEntries to namdtuples {dns_data} {lineno()}")
LOGGER.info(
f"Found entries from DDB for DNS records: {str(dns_data)} {lineno()}")
except Exception as err:
Expand Down Expand Up @@ -887,8 +884,21 @@ def lambda_handler(
LOGGER.info(
f"flags=noreverse, not adding PTR and heritage TXT for host {tag_data['ptr_entry'].hostname} zone {tag_data['ptr_entry'].zonename} value {final_private_dns_name}")

else: # not running so delete the records. Note this may leave orphans around if the flags are set and then the host is shut down. We may want to remove no matter what.
# else: # not running so delete the records. Note this may leave orphans around if the flags are set and then the host is shut down. We may want to remove no matter what.
# go through the dns_data records, and delete them. dns_data contains the records that were added. It is possible the tags have changed
# so using existing tag data will not be valid

if state != 'running':
if not flags['noforward']:
heritage_records = {}
for entry in dns_data:
if entry.rr_type == 'TXT' and entry.rr_value.startswith('heritage='):
heritage_records[entry.rr_name] = entry.rr_value
for entry in dns_data:
if not (entry.rr_type == 'TXT' and entry.rr_value.startswith('heritage=')):
process_response = new_process_delete_records(
instance_id, entry.zone_id, entry.rr_name, entry.zone_name, entry.rr_type, entry.rr_value, heritage_records.get(entry.rr_name, ''))

# Process and delete A record and associated TXT record
process_response = process_delete_records(
route53,
Expand Down Expand Up @@ -2734,6 +2744,12 @@ def publish_to_sns(client, message):
LOGGER.debug("No SNS Topic specified, ignoring")


def new_process_delete_records(instance_id, zone_id, record_name, zone_name, record_type, record_value, heritage_value):
LOGGER.info(
f"new delete records: instance {instance_id}, zone_id {zone_id}, name {record_name} zone_name {zone_name} type {record_type} value {record_value} heritage {heritage_value}")
return


def process_delete_records(route53, instance_id, zone_id,
record_name, zone_name, record_type, record_value, heritage_value):
"""
Expand All @@ -2745,6 +2761,7 @@ def process_delete_records(route53, instance_id, zone_id,
:param zone_name:
:param record_type:
:param record_value:
:param heritage_value:
:return response: # dictionary of 'delete_success' and 'msg'
"""

Expand Down
Binary file modified code/ddns-lambda.zip
Binary file not shown.

0 comments on commit f66cb0d

Please sign in to comment.