Created
January 3, 2024 11:39
-
-
Save olafz/9660d6275a80155da0719739d866ce42 to your computer and use it in GitHub Desktop.
This file is a patch for the `cloudns`py` file from the Python `dns-lexicon` package to properly support CAA, MX and SRV records. This patch-file only works for dns-lexicon up till 3.13, as 3.14 contains a significant rewrite.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- cloudns.py | |
+++ cloudns.py.patched | |
@@ -62,6 +62,24 @@ | |
if self._get_provider_option("port"): | |
params["port"] = self._get_lexicon_option("port") | |
+ if rtype == 'CAA': | |
+ caa_split = params['record'].split() | |
+ params['caa_flag'] = caa_split[0] | |
+ params['caa_type'] = caa_split[1] | |
+ params['caa_value'] = caa_split[2] | |
+ | |
+ if rtype == 'MX': | |
+ mx_split = params['record'].split() | |
+ params['priority'] = mx_split[0] | |
+ params['record'] = mx_split[1] | |
+ | |
+ if rtype == 'SRV': | |
+ srv_split = params['record'].split() | |
+ params['priority'] = srv_split[0] | |
+ params['weight'] = srv_split[1] | |
+ params['port'] = srv_split[2] | |
+ params['record'] = srv_split[3] | |
+ | |
# Add new record by calling the ClouDNS API | |
payload = self._post("/dns/add-record.json", params) | |
LOGGER.debug("create_record: %s", payload) | |
@@ -82,6 +100,17 @@ | |
payload = payload if not isinstance(payload, list) else {} | |
records = [] | |
for record in payload.values(): | |
+ if record['type'] == 'CAA': | |
+ record['record'] = '%s %s "%s"' % (record['caa_flag'], record['caa_type'], record['caa_value']) | |
+ | |
+ if record['type'] == 'MX': | |
+ if len(record['record']) == 0: | |
+ record['record'] = "." | |
+ record['record'] = '%s %s' % (record['priority'], record['record']) | |
+ | |
+ if record['type'] == 'SRV': | |
+ record['record'] = '%s %s %s %s.' % (record['priority'], record['weight'], record['port'], record['record']) | |
+ | |
records.append( | |
{ | |
"type": record["type"], | |
@@ -120,6 +149,24 @@ | |
if self._get_provider_option("port"): | |
params["port"] = self._get_provider_option("port") | |
+ if rtype == 'CAA': | |
+ caa_split = params['record'].split() | |
+ params['caa_flag'] = caa_split[0] | |
+ params['caa_type'] = caa_split[1] | |
+ params['caa_value'] = caa_split[2] | |
+ | |
+ if rtype == 'MX': | |
+ mx_split = params['record'].split() | |
+ params['priority'] = mx_split[0] | |
+ params['record'] = mx_split[1] | |
+ | |
+ if rtype == 'SRV': | |
+ srv_split = params['record'].split() | |
+ params['priority'] = srv_split[0] | |
+ params['weight'] = srv_split[1] | |
+ params['port'] = srv_split[2] | |
+ params['record'] = srv_split[3] | |
+ | |
# Update existing record by calling the ClouDNS API | |
payload = self._post("/dns/mod-record.json", params) | |
LOGGER.debug("update_record: %s", payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment