_get_root() rewritten for better API conformity

This commit is contained in:
peterkelm 2020-11-01 22:41:53 +01:00 committed by GitHub
parent f7732dcdb6
commit 1cb3568ab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,8 +27,6 @@ dns_variomedia_add() {
if ! _get_root "$fulldomain"; then if ! _get_root "$fulldomain"; then
return 1 return 1
fi fi
_debug _sub_domain "$_sub_domain"
_debug _domain "$_domain"
if ! _variomedia_rest POST "dns-records" "{\"data\": {\"type\": \"dns-record\", \"attributes\": {\"record_type\": \"TXT\", \"name\": \"$_sub_domain\", \"domain\": \"$_domain\", \"data\": \"$txtvalue\", \"ttl\":300}}}"; then if ! _variomedia_rest POST "dns-records" "{\"data\": {\"type\": \"dns-record\", \"attributes\": {\"record_type\": \"TXT\", \"name\": \"$_sub_domain\", \"domain\": \"$_domain\", \"data\": \"$txtvalue\", \"ttl\":300}}}"; then
_err "$response" _err "$response"
@ -59,8 +57,6 @@ dns_variomedia_rm() {
if ! _get_root "$fulldomain"; then if ! _get_root "$fulldomain"; then
return 1 return 1
fi fi
_debug _sub_domain "$_sub_domain"
_debug _domain "$_domain"
_debug 'Getting txt records' _debug 'Getting txt records'
@ -93,11 +89,12 @@ dns_variomedia_rm() {
# _sub_domain=_acme-challenge.www # _sub_domain=_acme-challenge.www
# _domain=domain.com # _domain=domain.com
_get_root() { _get_root() {
fulldomain=$1 domain=$1
i=1 i=2
p=1
while true; do while true; do
h=$(printf "%s" "$fulldomain" | cut -d . -f $i-100) h=$(printf "%s" "$domain" | cut -d . -f $i-100)
_debug h "$h"
if [ -z "$h" ]; then if [ -z "$h" ]; then
return 1 return 1
fi fi
@ -106,13 +103,15 @@ _get_root() {
return 1 return 1
fi fi
if _startswith "$response" "\{\"data\":"; then if _contains "$response" "\"id\":\"$h\""; then
if _contains "$response" "\"id\":\"$h\""; then _sub_domain=$(printf "%s" "$domain" | cut -d '.' -f 1-$p)
_sub_domain="$(echo "$fulldomain" | sed "s/\\.$h\$//")" _domain="$h"
_domain=$h
return 0 _debug _sub_domain "$_sub_domain"
fi _debug _domain "$_domain"
return 0
fi fi
p=$i
i=$(_math "$i" + 1) i=$(_math "$i" + 1)
done done