From dc86b605fee6bb6bf8695ec18037edf55051c20b Mon Sep 17 00:00:00 2001 From: Josef Vogt Date: Wed, 5 Feb 2020 09:42:56 +0100 Subject: [PATCH 1/5] Add support for octoDNS (multi-provider) --- dnsapi/dns_octodns.sh | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 dnsapi/dns_octodns.sh diff --git a/dnsapi/dns_octodns.sh b/dnsapi/dns_octodns.sh new file mode 100755 index 00000000..d40eef47 --- /dev/null +++ b/dnsapi/dns_octodns.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env sh + +# This API is a wrapper for other API so that you +# are able to put your TXT record to multiple providers. +# The functionality is in the responsibility of the respective API +# therefore please check if your used APIs work. +# e.g. for using NS1 and AWS Route53, use: +# OCTODNS_PROVIDERS=nsone_aws +# --dns octodns +# +# Author: Josef Vogt +# +######## Public functions ##################### +dns_octodns_add() { + fulldomain=$1 + txtvalue=$2 + _info "Creating DNS entries via octoDNS" + _debug fulldomain "$fulldomain" + _debug txtvalue "$txtvalue" + if [ -z "$OCTODNS_PROVIDERS" ]; then + OCTODNS_PROVIDERS="" + _err "You didn't specify OCTODNS_PROVIDERS yet." + _err "Please specifiy your providers and try again." + return 1 + fi + + #save the providers list to the account conf file. + _saveaccountconf OCTODNS_PROVIDERS "$OCTODNS_PROVIDERS" + return 1 + + IFS='_' read -r -a used_providers <<< "$OCTODNS_PROVIDERS" + for element in "${used_providers[@]}" + do + _debug element "$element" + sourcecommand="$_SUB_FOLDER_DNSAPI/dns_${element}.sh" + + if ! . "$sourcecommand"; then + _err "Load file $sourcecommand error. Please check your api file and try again." + return 1 + fi + + addcommand="dns_${element}_add" + _debug addcommand "$addcommand" + $addcommand "$fulldomain" "$txtvalue" + done + + _info "Finished adding records via octoDNS" + + return 0 +} + +#Remove the txt record after validation. +dns_octodns_rm() { + fulldomain=$1 + txtvalue=$2 + _info "Removing DNS entries via octoDNS" + _debug fulldomain "$fulldomain" + _debug txtvalue "$txtvalue" + + if [ -z "$OCTODNS_PROVIDERS" ]; then + OCTODNS_PROVIDERS="" + _err "You didn't specify OCTODNS_PROVIDERS yet." + _err "Please specifiy your providers and try again." + return 1 + fi + + IFS='_' read -r -a used_providers <<< "$OCTODNS_PROVIDERS" + for element in "${used_providers[@]}" + do + _debug element "$element" + sourcecommand="$_SUB_FOLDER_DNSAPI/dns_${element}.sh" + + if ! . "$sourcecommand"; then + _err "Load file $sourcecommand error. Please check your api file and try again." + return 1 + fi + + rmcommand="dns_${element}_rm" + _debug rmcommand "$rmcommand" + $rmcommand "$fulldomain" "$txtvalue" + done + + _info "Finished deleting records via octoDNS" + + return 0 +} From 0ed30db1d867af4ca235af47a975be5be354b999 Mon Sep 17 00:00:00 2001 From: Josef Vogt Date: Wed, 5 Feb 2020 14:48:49 +0100 Subject: [PATCH 2/5] Fixup bashism --- dnsapi/dns_octodns.sh | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/dnsapi/dns_octodns.sh b/dnsapi/dns_octodns.sh index d40eef47..51ddbd6a 100755 --- a/dnsapi/dns_octodns.sh +++ b/dnsapi/dns_octodns.sh @@ -26,14 +26,12 @@ dns_octodns_add() { #save the providers list to the account conf file. _saveaccountconf OCTODNS_PROVIDERS "$OCTODNS_PROVIDERS" - return 1 - IFS='_' read -r -a used_providers <<< "$OCTODNS_PROVIDERS" - for element in "${used_providers[@]}" - do + for element in $(echo "$OCTODNS_PROVIDERS" | tr "_" ' '); do _debug element "$element" sourcecommand="$_SUB_FOLDER_DNSAPI/dns_${element}.sh" + # shellcheck disable=SC1090 if ! . "$sourcecommand"; then _err "Load file $sourcecommand error. Please check your api file and try again." return 1 @@ -44,7 +42,7 @@ dns_octodns_add() { $addcommand "$fulldomain" "$txtvalue" done - _info "Finished adding records via octoDNS" + _info "Finished adding records via octoDNS API" return 0 } @@ -64,12 +62,11 @@ dns_octodns_rm() { return 1 fi - IFS='_' read -r -a used_providers <<< "$OCTODNS_PROVIDERS" - for element in "${used_providers[@]}" - do + for element in $(echo "$OCTODNS_PROVIDERS" | tr "_" ' '); do _debug element "$element" sourcecommand="$_SUB_FOLDER_DNSAPI/dns_${element}.sh" + # shellcheck disable=SC1090 if ! . "$sourcecommand"; then _err "Load file $sourcecommand error. Please check your api file and try again." return 1 @@ -80,7 +77,7 @@ dns_octodns_rm() { $rmcommand "$fulldomain" "$txtvalue" done - _info "Finished deleting records via octoDNS" + _info "Finished deleting records via octoDNS API" return 0 } From ec9c98df17e79e0f8288f91b3c29049f65fcba6b Mon Sep 17 00:00:00 2001 From: Josef Vogt Date: Wed, 5 Feb 2020 15:08:17 +0100 Subject: [PATCH 3/5] Fixup whitespace issue --- dnsapi/dns_octodns.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dnsapi/dns_octodns.sh b/dnsapi/dns_octodns.sh index 51ddbd6a..35086f07 100755 --- a/dnsapi/dns_octodns.sh +++ b/dnsapi/dns_octodns.sh @@ -43,7 +43,7 @@ dns_octodns_add() { done _info "Finished adding records via octoDNS API" - + return 0 } @@ -78,6 +78,6 @@ dns_octodns_rm() { done _info "Finished deleting records via octoDNS API" - + return 0 } From 24d5564596ba644aa2a156d38b424f60b934d3f8 Mon Sep 17 00:00:00 2001 From: Josef Vogt Date: Thu, 6 Feb 2020 16:37:43 +0100 Subject: [PATCH 4/5] Improve error handling --- dnsapi/dns_octodns.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dnsapi/dns_octodns.sh b/dnsapi/dns_octodns.sh index 35086f07..5d2caf60 100755 --- a/dnsapi/dns_octodns.sh +++ b/dnsapi/dns_octodns.sh @@ -39,7 +39,11 @@ dns_octodns_add() { addcommand="dns_${element}_add" _debug addcommand "$addcommand" - $addcommand "$fulldomain" "$txtvalue" + if ! $addcommand "$fulldomain" "$txtvalue"; then + _err "Adding record via $element API was not successful!" + _err "Please check if this API works." + return 1 + fi done _info "Finished adding records via octoDNS API" @@ -74,7 +78,12 @@ dns_octodns_rm() { rmcommand="dns_${element}_rm" _debug rmcommand "$rmcommand" - $rmcommand "$fulldomain" "$txtvalue" + if ! $rmcommand "$fulldomain" "$txtvalue"; then + _err "Removing record via $element API was not successful!" + _err "You might have to remove the key manually." + _err "Please check if this API works." + return 1 + fi done _info "Finished deleting records via octoDNS API" From 5e6b2ec6c121b111ae0f9c3ce0306502b6d07bbb Mon Sep 17 00:00:00 2001 From: Josef Vogt Date: Mon, 10 Feb 2020 15:39:59 +0100 Subject: [PATCH 5/5] Change save to save mutable --- dnsapi/dns_octodns.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsapi/dns_octodns.sh b/dnsapi/dns_octodns.sh index 5d2caf60..2bbec6fc 100755 --- a/dnsapi/dns_octodns.sh +++ b/dnsapi/dns_octodns.sh @@ -25,7 +25,7 @@ dns_octodns_add() { fi #save the providers list to the account conf file. - _saveaccountconf OCTODNS_PROVIDERS "$OCTODNS_PROVIDERS" + _saveaccountconf_mutable OCTODNS_PROVIDERS "$OCTODNS_PROVIDERS" for element in $(echo "$OCTODNS_PROVIDERS" | tr "_" ' '); do _debug element "$element"