# Find/isolate the root zone to work with in createRecord() and deleteRecord()
rootZone=""
if["$checkMultiZones"="true"];then
rootZone=$(for zone in$(echo"$result" | tr-d'\n'' ');do
if["$(echo"$domain" | grep"$zone")"!=""];then
_debug2 _get_root "- trying to figure out if $zone is in $domain"
echo"$zone"
break
fi
done)
#rootZone=$(for x in $(printf "%s" "${result3}" | tr ',' '\n' | sed -n 's/.*"name":"\(.*\)",.*/\1/p'); do if [ "$(echo "$domain" | grep "$x")" != "" ]; then echo "$x"; fi; done)
rootZone=$(for x in$(printf"%s\n""${result3}" | tr',''\n' | grep name | cut-d'"'-f4);do if["$(echo"$domain" | grep"$x")"!=""];then echo"$x";fi;done)
if["$rootZone"!=""];then
_debug2 _rootZone "- root zone for $domain is $rootZone"
else
_err "Could not find root zone for $domain, is it correctly typed?"
_err "You didn't specify a Yandex Cloud Zone ID or Folder ID yet."
return 1
fi
else
_err "YC_SA_Key_File not a RSA file(_isRSA function return false)."
return 1
fi
else
_err "YC_SA_Key_File not found in path $YC_SA_Key_File."
return 1
fi
else
_clearaccountconf YC_Zone_ID
_clearaccountconf YC_Folder_ID
_clearaccountconf YC_SA_ID
_clearaccountconf YC_SA_Key_ID
_clearaccountconf YC_SA_Key_File_PEM_b64
_clearaccountconf YC_SA_Key_File_Path
_err "You didn't specify a YC_SA_ID or YC_SA_Key_ID or YC_SA_Key_File."
return 1
fi
_debug "First detect the root zone"
if! _get_root "$fulldomain";then
_err "invalid domain"
return 1
fi
_debug _domain_id "$_domain_id"
_debug _sub_domain "$_sub_domain"
_debug _domain "$_domain"
_debug "Getting txt records"
if! _yc_rest GET "zones/${_domain_id}:getRecordSet?type=TXT&name=$_sub_domain";then
_err "Error: $response"
return 1
fi
_info "Adding record"
if _yc_rest POST "zones/$_domain_id:upsertRecordSets""{\"merges\": [ { \"name\":\"$_sub_domain\",\"type\":\"TXT\",\"ttl\":\"120\",\"data\":[\"$txtvalue\"]}]}";then
if _contains "$response""\"done\": true";then
_info "Added, OK"
return 0
else
_err "Add txt record error."
return 1
fi
fi
_err "Add txt record error."
return 1
}
#fulldomain txtvalue
dns_yc_rm(){
fulldomain="$(echo"$1". | _lower_case)"# Add dot at end of domain name
if _yc_rest POST "zones/$_domain_id:updateRecordSets""{\"deletions\": [ { \"name\":\"$_sub_domain\",\"type\":\"TXT\",\"ttl\":\"120\",\"data\":$exists_txtvalue}]}";then