Update _get_root logic

pull/5117/head
alviy 2024-04-26 23:05:42 +03:00 committed by GitHub
parent 03b53cbb60
commit 4bf4259dda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 20 deletions

View File

@ -103,28 +103,24 @@ dns_alviy_rm() {
_get_root() { _get_root() {
domain=$1 domain=$1
i=2 i=2
p=1 h=$(printf "%s" "$domain" | rev | cut -d . -f 1-2 | rev)
while true; do if [ -z "$h" ]; then
h=$(printf "%s" "$domain" | rev | cut -d . -f 1-2 | rev) #not valid
if [ -z "$h" ]; then _debug "can't get host from $domain"
#not valid return 1
return 1 fi
fi
if ! _alviy_rest GET "zone/$h/"; then if ! _alviy_rest GET "zone/$h/"; then
return 1 return 1
fi fi
if _contains "$response" '"code":"NOT_FOUND"'; then if _contains "$response" '"code":"NOT_FOUND"'; then
_debug "$h not found" _debug "$h not found"
else else
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) _sub_domain=$(printf "%s" "$domain" | rev | cut -d . -f 3- | rev)
_domain="$h" _domain="$h"
return 0 return 0
fi fi
p="$i"
i=$(_math "$i" + 1)
done
return 1 return 1
} }