From 3de712a7b0f09e4b6524246db66dc15e50091cac Mon Sep 17 00:00:00 2001 From: Yuan Ming Date: Thu, 13 Jan 2022 01:49:14 +0800 Subject: [PATCH] dns_huaweicloud.sh minor bug fixes 1. Match zone name in response in case multiple items return. 2. Use string '"id"' (single quotation marks added) to check if zone/record exist in _get_zoneid() & _get_recordset_id(). Fix domain can't contain string "id". --- dnsapi/dns_huaweicloud.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/dnsapi/dns_huaweicloud.sh b/dnsapi/dns_huaweicloud.sh index f7192725..dff9a1b2 100644 --- a/dnsapi/dns_huaweicloud.sh +++ b/dnsapi/dns_huaweicloud.sh @@ -129,14 +129,27 @@ _get_zoneid() { fi _debug "$h" response=$(_get "${dns_api}/v2/zones?name=${h}") - - if _contains "${response}" "id"; then - _debug "Get Zone ID Success." - _zoneid=$(echo "${response}" | _egrep_o "\"id\": *\"[^\"]*\"" | cut -d : -f 2 | tr -d \" | tr -d " ") - printf "%s" "${_zoneid}" - return 0 + _debug "$response" + if _contains "${response}" '"id"'; then + zoneidlist=$(echo "${response}" | _egrep_o "\"id\": *\"[^\"]*\"" | cut -d : -f 2 | tr -d \" | tr -d " ") + zonenamelist=$(echo "${response}" | _egrep_o "\"name\": *\"[^\"]*\"" | cut -d : -f 2 | tr -d \" | tr -d " ") + _debug "Return Zone ID(s):" + _debug "${zoneidlist}" + _debug "Return Zone Name(s):" + _debug "${zonenamelist}" + zoneidnum=0 + while read -r zonename; do + let zoneidnum++ + _debug "Check Zone Name $zonename" + if [[ $zonename == $h. ]]; then + _debug "Get Zone ID Success." + _zoneid=$(echo "${zoneidlist}" | sed -n $zoneidnum"p") + _debug "ZoneID:"$_zoneid + printf "%s" "${_zoneid}" + return 0 + fi + done <<< "$zonenamelist" fi - i=$(_math "$i" + 1) done return 1 @@ -149,7 +162,7 @@ _get_recordset_id() { export _H1="X-Auth-Token: ${_token}" response=$(_get "${dns_api}/v2/zones/${_zoneid}/recordsets?name=${_domain}") - if _contains "${response}" "id"; then + if _contains "${response}" '"id"'; then _id="$(echo "${response}" | _egrep_o "\"id\": *\"[^\"]*\"" | cut -d : -f 2 | tr -d \" | tr -d " ")" printf "%s" "${_id}" return 0