Open Cugar15 opened 6 years ago
Looks like something with the API has changed - adding a record such as @.domain.tld
was not the behaviour back when I initially developed this script - the API knew to interpret this as an apex record.
Will assign a couple of labels to this issue, and try to find some time to address it. Also added help wanted
label as my time is very limited at present 😞
Thanks for the bug report!
I did a bit of digging and here are my findings:
1) the clouDNS api returns whatever is specified under host. If host is empty and empty value is returned. 2) to query a record with a blank host, host=@ needs to be used. 3) the script converts an empty host value to @ and then the @ is added for hostname
I think, the bug is in this statement:
366 if [ "${JSON}" -eq "1" ]; then
367 if [ "${HOST_RECORD}" = "@" ]; then
368 builtin echo "${RECORD_DATA}" | jq -r '.[] | select(.host == "")'
369 else
370 builtin echo "${RECORD_DATA}" | jq -r '.'
371 fi
372 exit 0
373 fi
My recommendation is change line 368 to:
builtin echo "${RECORD_DATA}" | jq -r '.[] | select((.host == "") or (.host == "@"))'
That way, next time, around the script recognizes @ as well.
A clean way might be to not map @ to ''. The API seems to accept a missing host - despite the docu specifies required. However these modifications need to be made in the modify_record routine when parsing the return of the list_record command which is executed inside of modify_record.
Warning: I did NOT test any other side effects of my suggestions.
On top, I recommend to pipe the print_debug statements to stderr. That way all debug messages will be printed on the console and are not i.e. piped in to variables. This makes it easier to debug.
Hope this helps.
This is great information, thank you @Cugar15.
I am extremely busy with my day job and other matters, but if you'd like to raise a PR to address this, I'd be very happy to review. Even just a PR to direct print_debug
to STDERR in the interim - that's a great idea.
Cheers
Hi,
I'm having trouble with API.
1) In the GUI interface of clouDNS, the host information is left blank. 2) To modify the record, the following command is issued : MOD_ID=
cloudns_api.sh -sj listrecords $ZONE host=@ type=A showid=true | jq --raw-output '.id'
echo 'ID :' ${MOD_ID} cloudns_api.sh -s modify $ZONE id=${MOD_ID} record=${IP_A}This works, but also adds '@' for the host.
3) Applying list records again: cloudns_api.sh -sj listrecords $ZONE host=@ type=A showid=true
does not return a record??
Any help which can be provided?
Thanks!