diff --git a/code/ddns-lambda.py b/code/ddns-lambda.py index e5117ec..3d894d7 100755 --- a/code/ddns-lambda.py +++ b/code/ddns-lambda.py @@ -73,7 +73,7 @@ LOGGER = logging.getLogger() account_id = None region = None -VERSION = '1.2.0b35' +VERSION = '1.2.0b36' # Read Env variables DEBUG_LOG_LEVEL = os.environ.get('DebugLogLevel', 'INFO') @@ -1565,7 +1565,7 @@ def new_change_resource_recordset(oclient, instance_id, zone_id, host_name, host { "Action": "UPSERT", "ResourceRecordSet": { - "Name": host_name, + "Name": create_fqdn(host_name, hosted_zone_name), "Type": record_type, "TTL": DNS_RR_TTL, "ResourceRecords": [ @@ -1953,7 +1953,7 @@ def new_delete_resource_record(oclient, instance_id, zone_id, host_name, hosted_ { "Action": "DELETE", "ResourceRecordSet": { - "Name": host_name, + "Name": create_fqdn(host_name, hosted_zone_name), "Type": record_type, "TTL": DNS_RR_TTL, "ResourceRecords": [ @@ -2209,7 +2209,7 @@ def new_reverse_entry(ip_list): """ Reverses the order of the instance's IP address and helps construct the reverse lookup zone name. :param str ip_list: IPv4 address to reverse - :return str: Returns a string in the PTR format + :return str: Returns a string in the PTR format (with trailing dot) """ try: ip = ipaddress.ip_address(ip_list) @@ -3117,3 +3117,19 @@ def parse_hostname_to_components(name): # noforward # noreverse # noheritage + +def create_fqdn(host, zone): + """ + This takes a hostname (may or nay not be FQDN) and a zone, and returns the proper concatenation of the two, with a trailing dot. + + :param str host: hostname (short or FQDN) + :param str zone: zone name + :return (str,str): Tuple containing hostname components (may include dot) and domain name for which a PHZ exists. None is returned if not found. + """ + + hh = parse_hostname_to_components(name) + if hh[1] == '': + hh[1] = zone + fqdn = hh[0] + '.' + hh[1] + fqdn += '.' if fqdn[-1] != '.' else '' + return fqdn diff --git a/code/ddns-lambda.zip b/code/ddns-lambda.zip index 414871c..fef7412 100644 Binary files a/code/ddns-lambda.zip and b/code/ddns-lambda.zip differ