diff --git a/dnsapi/dns_poweradmin.sh b/dnsapi/dns_poweradmin.sh index a4c81835..2ae86347 100644 --- a/dnsapi/dns_poweradmin.sh +++ b/dnsapi/dns_poweradmin.sh @@ -114,21 +114,32 @@ _rm_record() { full=$1 txtvalue=$2 - if ! _poweradmin_rest "GET" "/api/v${POWERADMIN_API_VERSION}/zones/$_zone_id/records"; then + if ! _poweradmin_rest "GET" "/api/v${POWERADMIN_API_VERSION}/zones/$_zone_id/records?type=TXT"; then _err "Failed to retrieve records" return 1 fi - # The API returns: {"success":true,"data":[{"id":..., "name":"...", "type":"TXT", "content":"...", ...}]} - _txt_record_obj=$( - printf '%s\n' "$response" | - sed 's/^.*"data":\[//; s/\],"message":.*$//' | - awk '{ gsub(/},{/, "}\n{"); print }' | - grep -F "\"name\":\"$full\"" | - grep -F "\"type\":\"TXT\"" | - grep -F "\"content\":\"$txtvalue\"" | - _head_n 1 - ) + # The API returns: {"success":true,"data":{"records":[{"id":..., "name":"...", "type":"TXT", "content":"...", ...}]},"message":"..."} + _records="$(printf '%s\n' "$response" | tr -d '\r\n' | _egrep_o '\{[^{}]*\}')" + _txt_record_obj="" + while IFS= read -r _rec || [ -n "$_rec" ]; do + case "$_rec" in + *"\"name\":\"$full\""*) ;; + *) continue ;; + esac + case "$_rec" in + *"\"type\":\"TXT\""*) ;; + *) continue ;; + esac + case "$_rec" in + *"\"content\":\"$txtvalue\""*) + _txt_record_obj="$_rec" + break + ;; + esac + done <