Browse Source

fix pagination bug querying Linode API v4

fixes issue #4956

previous code only worked for the first 10 domains on the account (as Linode
API returned a paginated response, with only 10 records).

This change makes an exact search query for each subdomain, completely removing any
need for walking through paginated responses. What makes it work for large
accounts with any number of domains.
pull/5172/head
Vinicius Mello 3 months ago
parent
commit
1c9423ef31
  1. 22
      dnsapi/dns_linode_v4.sh

22
dnsapi/dns_linode_v4.sh

@ -126,34 +126,41 @@ _Linode_API() {
# _domain=domain.com # _domain=domain.com
# _domain_id=12345 # _domain_id=12345
_get_root() { _get_root() {
domain=$1
local full_host_str="$1"
i=2 i=2
p=1 p=1
if _rest GET; then
response="$(echo "$response" | tr -d "\n" | tr '{' "|" | sed 's/|/&{/g' | tr "|" "\n")"
while true; do while true; do
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
# loop through the received string (e.g. _acme-challenge.sub3.sub2.sub1.domain.tld),
# starting from the lowest subdomain, and check if it's a hosted domain
h=$(printf "%s" "$full_host_str" | cut -d . -f $i-100)
_debug h "$h" _debug h "$h"
if [ -z "$h" ]; then if [ -z "$h" ]; then
#not valid #not valid
return 1 return 1
fi fi
_debug "Querying Linode APIv4 for subdomain: $h"
if _H4="X-Filter: {\"domain\":\"$h\"}" _rest GET; then
_debug "Got response from API: $response"
response="$(echo "$response" | tr -d "\n" | tr '{' "|" | sed 's/|/&{/g' | tr "|" "\n")"
hostedzone="$(echo "$response" | _egrep_o "\{.*\"domain\": *\"$h\".*}")" hostedzone="$(echo "$response" | _egrep_o "\{.*\"domain\": *\"$h\".*}")"
if [ "$hostedzone" ]; then if [ "$hostedzone" ]; then
_domain_id=$(printf "%s\n" "$hostedzone" | _egrep_o "\"id\": *[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ ) _domain_id=$(printf "%s\n" "$hostedzone" | _egrep_o "\"id\": *[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ )
_debug "Found domain hosted on Linode DNS. Zone: $h, id: $_domain_id"
if [ "$_domain_id" ]; then if [ "$_domain_id" ]; then
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
_sub_domain=$(printf "%s" "$full_host_str" | cut -d . -f 1-$p)
_domain=$h _domain=$h
return 0 return 0
fi fi
return 1 return 1
fi fi
p=$i p=$i
i=$(_math "$i" + 1) i=$(_math "$i" + 1)
done
fi fi
done
return 1 return 1
} }
@ -169,6 +176,7 @@ _rest() {
export _H1="Accept: application/json" export _H1="Accept: application/json"
export _H2="Content-Type: application/json" export _H2="Content-Type: application/json"
export _H3="Authorization: Bearer $LINODE_V4_API_KEY" export _H3="Authorization: Bearer $LINODE_V4_API_KEY"
export _H4 # used to query for the root domain on _get_root()
if [ "$mtd" != "GET" ]; then if [ "$mtd" != "GET" ]; then
# both POST and DELETE. # both POST and DELETE.

Loading…
Cancel
Save