Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Apr 27, 2023
1 parent b723eab commit e778f86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
29 changes: 17 additions & 12 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.0b78'
VERSION = '1.2.0b80'

# Read Env variables
DEBUG_LOG_LEVEL = os.environ.get('DebugLogLevel', 'INFO')
Expand Down Expand Up @@ -689,6 +689,8 @@ def lambda_handler(
f_hostname = tag_data['option_name'].hostname
f_zonename = tag_data['option_name'].zonename
elif not tag_data['option_name'].valid and tag_data['option_name'].hostname and tag_data['dhcp_options'].valid:
LOGGER.info(
f"2.2 instance: {instance_id}, using tag_option.name hostname {tag_data['option_name'].hostname} and and tag_option.name zone {tag_data['option_name'].zonename}")
f_hostname = tag_data['option_name'].hostname
f_zonename = tag_data['dhcp_options'].zonename
elif tag_data['name'].valid:
Expand Down Expand Up @@ -3069,11 +3071,11 @@ def process_tags_flags(tags):
"""
Process the DNS flags tags into for tags[key]=='boc:dns:flags'
:param list(dict(string)) tags: tags from instance, list of dict of string
:param list(dict(string)) tags: tags from instance, list of dict of string. Keys and values turned to lowercase.
:return dict(string): flag settings in defaultdict for controlling which names are registered and when
"""

tag_dict = {tag['Key'].lstrip().lower(): tag['Value'] for tag in tags}
tag_dict = {tag['Key'].lstrip().lower(): tag['Value'].lower() for tag in tags}
flags_dict = defaultdict(lambda: False)
flags = tag_dict.get(TAGKEY_FLAGS.lower(), '').split(',')
for flag in flags:
Expand All @@ -3093,9 +3095,10 @@ def process_tags_value(name):
"""

if name != '':
components = parse_hostname_to_components(name)
if components:
return (True, components[0], components[1])
return parse_hostname_to_components(name)
# components = parse_hostname_to_components(name)
# if components:
# return (True, components[0], components[1])
return (False, name, None)


Expand Down Expand Up @@ -3200,10 +3203,10 @@ def parse_hostname_to_components(name):
the Name, boc:dns:cname or boc:dns:name tags contain myhost.db.common.edl.census.gov, and the zone is common.edl.census.gov,
simply checking at the first dot (host==myhost, domain==db.common.edl.census.gov) will fail. This will go through the
list of PHZs found for the VPC for each of the possible domains, and return the name components if a match is found.
That returned name/zone shoudl be used for all settings.
That returned name/zone shoudl be used for all settings. If the zone is not found it will parse into first part before dot, remainder.
:param str name: FQDN to parse and find existing defined PHZ
:return (str,str): Tuple containing hostname components (may include dot) and domain name for which a PHZ exists. None is returned if not found.
:return (bool,str,str): Tuple containing found-PHZ (True|False), hostname components (may include dot) and domain name for which a PHZ exists. None is returned if not found.
"""

global phz_collection_by_vpc
Expand All @@ -3212,10 +3215,12 @@ def parse_hostname_to_components(name):
host = '.'.join(names[0:i])
domain = '.'.join(names[i:]) + '.'
if phz_collection_by_vpc.get(domain):
return (host, domain)
LOGGER.error(
f"No PHZ found for any domain components of {name} associated with this vpc: {lineno()}")
return None
return (True, host, domain)
host = name[0]
domain = '.'.join(names[1:]) + '.'
LOGGER.info(
f"No PHZ found for any domain components of {name} associated with this vpc, returing host {host} domain {domain}: {lineno()}")
return (False, host, domain)


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

0 comments on commit e778f86

Please sign in to comment.