Skip to content

Commit 0d61bfc

Browse files
committed
dns_dynadot: optionally retry failed api calls
1 parent 1ce1de2 commit 0d61bfc

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

dnsapi/dns_dynadot.sh

+51-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# Create a dynadot api key under the web portal "Tools > API" and export that for this script:
77
# export DYNADOTAPI_Token="ASDF1234ASDF1234"
88
#
9+
# export DYNADOTAPI_API_RETRIES=1 (optional) Number of times to attempt Dynadot API call until success (default=1)
10+
# export DYNADOTAPI_RETRY_SLEEP=30 (optional) Seconds to sleep between retry attempts (default: 30 seconds)
11+
#
912
# Important notes:
1013
# At the time of writing this integration, there are some quirks with the Dynadot APIs:
1114
#
@@ -50,10 +53,21 @@ dns_dynadot_add() {
5053
_err "Please create your token and try again."
5154
return 1
5255
fi
53-
5456
#save the credentials to the account conf file.
5557
_saveaccountconf_mutable DYNADOTAPI_Token "$DYNADOTAPI_Token"
5658

59+
DYNADOTAPI_API_RETRIES="${DYNADOTAPI_API_RETRIES:-$(_readaccountconf_mutable DYNADOTAPI_API_RETRIES)}"
60+
if [ -z "$DYNADOTAPI_API_RETRIES" ]; then
61+
DYNADOTAPI_API_RETRIES=1
62+
fi
63+
_saveaccountconf_mutable DYNADOTAPI_API_RETRIES "$DYNADOTAPI_API_RETRIES"
64+
65+
DYNADOTAPI_RETRY_SLEEP="${DYNADOTAPI_RETRY_SLEEP:-$(_readaccountconf_mutable DYNADOTAPI_RETRY_SLEEP)}"
66+
if [ -z "$DYNADOTAPI_RETRY_SLEEP" ]; then
67+
DYNADOTAPI_RETRY_SLEEP=30
68+
fi
69+
_saveaccountconf_mutable DYNADOTAPI_RETRY_SLEEP "$DYNADOTAPI_RETRY_SLEEP"
70+
5771
_debug "DYNADOT: Detecting root domain"
5872
if ! _get_root "$fulldomain"; then
5973
_err "invalid domain"
@@ -83,6 +97,11 @@ dns_dynadot_add() {
8397
return 1
8498
fi
8599

100+
if [ "$DYNADOTAPI_TEST_SLEEP" ]; then
101+
_debug "DYNADOT: Test Mode. Sleeping $DYNADOTAPI_TEST_SLEEP seconds."
102+
sleep "$DYNADOTAPI_TEST_SLEEP"
103+
fi
104+
86105
_info "DYNADOT: TXT record added successfully"
87106
return 0
88107
}
@@ -93,6 +112,11 @@ dns_dynadot_rm() {
93112
fulldomain=$1
94113
txtvalue=$2
95114

115+
if [ "$DYNADOTAPI_SKIP_REMOVE" = "SKIP" ]; then
116+
_debug "DYNADOT: Skipping removal. Please remove manually."
117+
return 0
118+
fi
119+
96120
_info "DYNADOT: Removing TXT Record"
97121
_debug "DYNADOT: fulldomain: $fulldomain"
98122
_debug "DYNADOT: txtvalue: $txtvalue"
@@ -344,6 +368,32 @@ _dynadot_rm_txt_entry() {
344368

345369
_dynadot_rest() {
346370
url_params=$1
371+
372+
_retry_attempts="$DYNADOTAPI_API_RETRIES"
373+
_retry_sleep="$DYNADOTAPI_RETRY_SLEEP"
374+
375+
while true; do
376+
if _dynadot_rest_call "$url_params"; then
377+
return 0
378+
fi
379+
380+
_retry_attempts=$(_math "$_retry_attempts" - 1)
381+
382+
if [ "${_retry_attempts}" -lt "1" ]; then
383+
_err "DYNADOT: api call failed all retry attempts."
384+
return 1
385+
fi
386+
387+
_info "DYNADOT: api call failed. Retrying up to $_retry_attempts times. Sleeping $_retry_sleep seconds before retry."
388+
sleep "$_retry_sleep"
389+
done
390+
391+
# We should not get to the bottom of this function
392+
return 1
393+
}
394+
395+
_dynadot_rest_call() {
396+
url_params=$1
347397
token_trimmed=$(echo "$DYNADOTAPI_Token" | tr -d '"')
348398

349399
_debug "DYNADOT: Calling dynadot API: $url_params"

0 commit comments

Comments
 (0)