Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Apr 25, 2023
1 parent de2d3de commit 9fa9abd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 39 deletions.
65 changes: 26 additions & 39 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.0b40'
VERSION = '1.2.0b41'

# Read Env variables
DEBUG_LOG_LEVEL = os.environ.get('DebugLogLevel', 'INFO')
Expand Down Expand Up @@ -683,21 +683,19 @@ def lambda_handler(
instance_id, f_hostname, f_zonename, str(final_private_dns_name), lineno())

# Get the PHZ ID for the Zone
final_hosted_zone_item = phz_collection_by_vpc[final_hosted_zone_name]
final_hosted_zone_id = final_hosted_zone_item['zone_id']
zone_data_forward = zone_data_tuple(
*phz_collection_by_vpc[final_hosted_zone_name].values())
zone_data_reverse = zone_data_tuple(
*phz_collection_by_vpc[tag_data['ptr_entry'].zonename].values())
## final_hosted_zone_item = phz_collection_by_vpc[final_hosted_zone_name]
## final_hosted_zone_id = zone_data_forward.zone_id
## final_hosted_zone_owner = final_hosted_zone_item['owner_account']

LOGGER.info(f"zone_data_forward: {pformat(zone_data_forward)}")
LOGGER.info(f"zone_data_reverse: {pformat(zone_data_reverse)}")

LOGGER.debug("private_hosted_zone_id:"
" %s", str(final_hosted_zone_id) + lineno())
final_hosted_zone_owner = final_hosted_zone_item['owner_account']
LOGGER.debug("private_hosted_zone_owner: is_mine %s"
" %s", final_hosted_zone_owner == account_id, str(final_hosted_zone_owner) + lineno())
LOGGER.debug(
f"private_hosted_zone: zone_id {zone_data_forward.zone_id} is_mine {zone_data_forward.owner_account==account_id} owner {zone_data_forward.owner_account}: {lineno()}")

# create the TXT heritage record
heritage = initialize_heritage(HERITAGE_TAG, VERSION,
Expand Down Expand Up @@ -725,13 +723,13 @@ def lambda_handler(
create_response = create_resource_record(
route53,
instance_id,
final_hosted_zone_id,
zone_data_forward.zone_id,
final_private_hostname,
final_hosted_zone_name,
zone_data_forward.name, ,
'A',
private_ip
)
append_msg = f"A record in zone id: {final_hosted_zone_id} for hostname {final_private_hostname} " + \
append_msg = f"A record in zone id: {zone_data_forward.zone_id} owner {zone_data_forward.owner_account} for hostname {final_private_hostname} " + \
f"zone {final_hosted_zone_name} to value {private_ip}"
count[create_response] += 1
if create_response == 'success':
Expand All @@ -749,19 +747,19 @@ def lambda_handler(
try:
if not flags['noheritage']:
if len(heritage) > 0:
LOGGER.debug("Creating heritage TXT resource records %s, with a value of %s",
final_private_hostname, str(heritage_value) + lineno())
LOGGER.debug(
f"Creating heritage TXT resource records {final_private_hostname} with value {heritage_value}: {lineno()}")
create_response = create_resource_record(
route53,
instance_id,
final_hosted_zone_id,
zone_data_forward.zone_id,
final_private_hostname,
final_hosted_zone_name,
zone_data_forward.name,
'TXT',
heritage_value
)
append_msg = f"TXT record in zone id: {reverse_lookup_zone_id} for hostname {final_private_hostname} " + \
f"zone {final_hosted_zone_name} to value {heritage_value}"
append_msg = f"TXT record in zone id: {zone_data_forward.zone_id} owner {zone_data_forward.owner_account} for hostname {final_private_hostname} " + \
f"zone {zone_data_forward.name} to value {heritage_value}"

count[create_response] += 1
if create_response == 'success':
Expand All @@ -784,13 +782,13 @@ def lambda_handler(
create_response = create_resource_record(
route53,
instance_id,
reverse_lookup_zone_id,
zone_data_reverse.zone_id,
tag_data['ptr_entry'].hostname,
tag_data['ptr_entry'].zonename,
'PTR',
create_fqdn(final_private_hostname, final_hosted_zone_name),
)
append_msg = f"PTR record in zone id: {reverse_lookup_zone_id} for hostname {tag_data['ptr_entry'].hostname} " + \
append_msg = f"PTR record in zone id: {zone_data_reverse.zone_id} owner {zone_data_reverse.owner_id} for hostname {tag_data['ptr_entry'].hostname} " + \
f"zone {tag_data['ptr_entry'].zonename} to value {final_private_dns_name}"
count[create_response] += 1
if create_response == 'success':
Expand All @@ -809,18 +807,18 @@ def lambda_handler(
try:
if not flags['noheritage']:
if reverse_zone_associated and len(heritage) > 0:
LOGGER.debug("Creating heritage TXT resource records %s, with a value of %s",
str(reversed_ip_address), str(heritage_value) + lineno())
LOGGER.debug(
f"Creating heritage TXT resource records {tag_data['ptr_entry'].hostname} with value {heritage_value}: {lineno()}")
create_response = create_resource_record(
route53,
instance_id,
reverse_lookup_zone_id,
zone_data_reverse.zone_id,
tag_data['ptr_entry'].hostname,
tag_data['ptr_entry'].zonename,
'TXT',
heritage_value
)
append_msg = f"TXT record in zone id: {reverse_lookup_zone_id} for hostname {tag_data['ptr_entry'].hostname} " + \
append_msg = f"TXT record in zone id: {zone_data_reverse.zone_id} owner {zone_data_reverse.owner_id} for hostname {tag_data['ptr_entry'].hostname} " + \
f"zone {tag_data['ptr_entry'].zonename} to value {heritage_value}"

count[create_response] += 1
Expand All @@ -839,7 +837,7 @@ def lambda_handler(
instance_id, str(err) + lineno())

else: # not running so delete the records
if not flags['nofoward']:
if not flags['noforward']:
# Process and delete A record and associated TXT record
process_response = process_delete_records(
route53,
Expand Down Expand Up @@ -910,13 +908,8 @@ def lambda_handler(
'CNAME',
final_private_dns_name
)
append_msg = 'CNAME record in zone id: ' + \
str(cname_domain_suffix_id) + \
' for hosted zone ' + \
str(cname_host_name) + '.' + \
str(cname_domain_suffix) + \
' with value: ' + \
str(final_private_dns_name)
append_msg = f"CNAME record in zone id: {cname_domain_suffix_id} owner {phz_collection_by_vpc[cname_domain_suffix]['owner_account']} " + \
f"hostname {cname_host_name} in zone {cname_domain_suffix} with value {final_private_dns_name}"

if create_response == 'success':
LOGGER.info("instance: %s, Created %s",
Expand Down Expand Up @@ -944,14 +937,8 @@ def lambda_handler(
'TXT',
heritage_value
)
append_msg = 'TXT for CNAME record in zone id: ' + \
str(cname_domain_suffix_id) + \
' for hosted zone ' + \
str(TXT_RR_PREFIX) + '.' + \
str(cname_host_name) + '.' + \
str(cname_domain_suffix) + \
' with value: ' + \
str(heritage_value)
append_msg = f"TXT for CNAME record in zone id: {cname_domain_suffix_id} owner phz_collection_by_vpc[cname_domain_suffix]['owner_account']} " + \
f"hostname {cname_host_name} in zone {cname_domain_suffix} with value {heritage_value}"

if create_response == 'success':
LOGGER.info("instance: %s, Created %s",
Expand Down
Binary file modified code/ddns-lambda.zip
Binary file not shown.

0 comments on commit 9fa9abd

Please sign in to comment.