diff --git a/CHANGELOG.md b/CHANGELOG.md index e6035f2..1d4585e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,3 +29,7 @@ * 0.0.21 -- 2022-02-17 - update code 0.0.12 - add heritage functions, but not include anywhere to call them + +* 0.0.22 -- 2022-02-22 + - code 0.0.13 + - fix typo diff --git a/code/ddns-lambda.py b/code/ddns-lambda.py index 521dac1..309f630 100755 --- a/code/ddns-lambda.py +++ b/code/ddns-lambda.py @@ -72,7 +72,7 @@ LOGGER = logging.getLogger() ACCOUNT = None REGION = None -VERSION = '0.0.12' +VERSION = '0.0.13' # Adjust the logging level [logging.INFO, logging.DEBUG, logging.WARNING, etc] LOGGER.setLevel(logging.DEBUG) @@ -200,7 +200,7 @@ def lambda_handler( # if key attributes are found, then break out of the loop if all([t_private_ip, t_private_dns_name, t_subnet_id, t_vpc_id]): LOGGER.debug("instance data found, exiting while loop: " - "%s", t_private_dns_name + "," + t_private_ip + "," + t_subnet_id + "," + t_vpc_id + lineno()) + "%s", t_private_dns_name + "," + t_private_ip + "," + t_subnet_id + "," + t_vpc_id + lineno()) break except: LOGGER.info("no instance data, repeat check: %s", lineno()) @@ -408,7 +408,7 @@ def lambda_handler( custom_zone_name = custom_zone_name + '.' LOGGER.debug("Checking if custom_zone_name is valid: %s", - str(custom_zone_name) + lineno()) + str(custom_zone_name) + lineno()) # check if the zone is already validated, if not check if custom_zone_name in valid_dns_zones: @@ -1172,17 +1172,17 @@ def is_valid_zone(route53, zonename, hosted_zones, vpc_id, private_hosted_zone_c LOGGER.debug("in function is_valid_zone") LOGGER.debug("Looking to validate zone: %s", - zonename + lineno()) + zonename + lineno()) try: # check if the zone is PHZ if zonename.lower() in private_hosted_zone_collection: LOGGER.debug("Private zone found: %s", - zonename + lineno()) + zonename + lineno()) hosted_zone_id = get_zone_id(zonename, hosted_zones) LOGGER.debug("hosted_zone_id: %s", - hosted_zone_id + lineno()) + hosted_zone_id + lineno()) private_hosted_zone_properties = get_hosted_zone_properties( route53, @@ -1194,14 +1194,14 @@ def is_valid_zone(route53, zonename, hosted_zones, vpc_id, private_hosted_zone_c # check if the VPC is associated with the PHZ if vpc_id in map(lambda x: x['VPCId'], private_hosted_zone_properties['VPCs']): LOGGER.debug("Privated Hosted Zone associated with VPC: %s", - zonename + lineno()) + zonename + lineno()) return True else: LOGGER.debug("Private Hosted Zone is NOT associated with vpc: %s", - zonename + lineno()) + zonename + lineno()) else: LOGGER.debug("Domain Name does not match Private Hosted Zones: %s", - zonename + lineno()) + zonename + lineno()) # if returned with True, return false return False @@ -1403,99 +1403,100 @@ def get_subnet_cidr_block(client, subnet_id): def initialize_heritage(application_name, version='null', items={}): - """ - Initialize the heritage datastructure (dict). - :param str application_name: The application name. Shoud not have spaces. An empty application name will return an empty dict. - :param str version: A version of the specific implementation that created this. Versions are primarily for documenting what created the record TXT record. - :param dict(str) items: A dict of key/value pairs to set on initialization. They key of version is not permitted here. - :return dict(str): dict with the application name, version, and items ready for use - """ - if application_name != '' and appication_name is not none: - return { - 'application_name': str(appname), - 'version': str(version), - 'items': OrderedDict(items), - } - else: - return {} + """ + Initialize the heritage datastructure (dict). + :param str application_name: The application name. Shoud not have spaces. An empty application name will return an empty dict. + :param str version: A version of the specific implementation that created this. Versions are primarily for documenting what created the record TXT record. + :param dict(str) items: A dict of key/value pairs to set on initialization. They key of version is not permitted here. + :return dict(str): dict with the application name, version, and items ready for use + """ + if application_name != '' and appication_name is not none: + return { + 'application_name': str(appname), + 'version': str(version), + 'items': OrderedDict(items), + } + else: + return {} def dump_heritage(data): - """ - Dump the heritage dict into a string. - :param dict(string): Dictionary containing heritage data - :return dict(string): string format of dict - """ - return pformat(data) + """ + Dump the heritage dict into a string. + :param dict(string): Dictionary containing heritage data + :return dict(string): string format of dict + """ + return pformat(data) def add_heritage_item(data, key, value): - """ - Add a key/value pair to the heritage dict. - :param dict(string) data: Dictionary containing heritage data - :param str key: The key for the key/value pair - :param str value: The value for the key/value pair - :return: This adds the key/value pair to the heritage dict items. There is no return value. - """ - data['items'][str(key)] = str(value) + """ + Add a key/value pair to the heritage dict. + :param dict(string) data: Dictionary containing heritage data + :param str key: The key for the key/value pair + :param str value: The value for the key/value pair + :return: This adds the key/value pair to the heritage dict items. There is no return value. + """ + data['items'][str(key)] = str(value) def add_heritage_item_timestamp(data, key): - """ - Add an epoch timestamp to the named field in key. - :param dict(string) data: Dictionary containing heritage data - :param str key: The key for the key to contain the timestamp - :return: This adds the key and current timestamp to the heritage dict items. There is no return value. - """ - data['items'][str(key)] = int(datetime.now().timestamp()) + """ + Add an epoch timestamp to the named field in key. + :param dict(string) data: Dictionary containing heritage data + :param str key: The key for the key to contain the timestamp + :return: This adds the key and current timestamp to the heritage dict items. There is no return value. + """ + data['items'][str(key)] = int(datetime.now().timestamp()) def format_heritage(data): - """ - Return the TXT record format of the heritage data structure. This is of the format - heritage={app},{app}/version={version},{app}/{key}={value},... + """ + Return the TXT record format of the heritage data structure. This is of the format + heritage={app},{app}/version={version},{app}/{key}={value},... - :param dict(string) data: Dictionary containing heritage data - :return str: This returns a string with the formatted heritage data comma separated - """ - appname = data['application_name'] - output = ['heritage={},{}/version={}'.format(appname, appname, data['version'])] - for k, v in data['items'].items(): - output.append('{}/{}={}'.format(appname, k, v)) - return ','.join(output) + :param dict(string) data: Dictionary containing heritage data + :return str: This returns a string with the formatted heritage data comma separated + """ + appname = data['application_name'] + output = ['heritage={},{}/version={}'.format(appname, appname, data['version'])] + for k, v in data['items'].items(): + output.append('{}/{}={}'.format(appname, k, v)) + return ','.join(output) def parse_heritage(info): - """ - Take a TXT record and parse it into a heritage dict. - :param str info: string with TXT record of heritage data - :return dict(str): Heritage dict - kv_results={} - kv=info.split(',') + """ + Take a TXT record and parse it into a heritage dict. + :param str info: string with TXT record of heritage data + :return dict(str): Heritage dict + """ + kv_results = {} + kv = info.split(',') # print(kv) - header=kv.pop(0).split('=') - - if header[0]!='heritage': - return kv_results - else: - appname=header[1] - kv_results['application_name']=appname - try: - for item in kv: - k,v=item.split('=',2) + header = kv.pop(0).split('=') + + if header[0] != 'heritage': + return kv_results + else: + appname = header[1] + kv_results['application_name'] = appname + try: + for item in kv: + k, v = item.split('=', 2) # print('appname',appname,'k',k,'v',v) - if appname+'/' in k: - nk=k.replace(appname+'/','') - kv_results[nk]=v + if appname + '/' in k: + nk = k.replace(appname + '/', '') + kv_results[nk] = v # print('nk',nk) - if kv_results.get('version') is None: -# version=kv_result.pop('version') -# else: - version='null' + if kv_results.get('version') is None: + # version=kv_result.pop('version') + # else: + version = 'null' # return initialize_heritage(appname,version,kv_results) - return kv_results - except: - return {} + return kv_results + except: + return {} # heritage examples to incorporate # h=initialize_heritage('dynr53','0.0.9') diff --git a/code/ddns-lambda.zip b/code/ddns-lambda.zip index 89902c6..ba3ca7c 100644 Binary files a/code/ddns-lambda.zip and b/code/ddns-lambda.zip differ diff --git a/version.tf b/version.tf index 3ca2fc8..ac63989 100644 --- a/version.tf +++ b/version.tf @@ -1,3 +1,3 @@ locals { - _module_version = "0.0.21" + _module_version = "0.0.22" }