Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listrecords with host=@ does not work #10

Open
Cugar15 opened this issue Jun 11, 2018 · 3 comments
Open

listrecords with host=@ does not work #10

Cugar15 opened this issue Jun 11, 2018 · 3 comments
Labels
API Issues caused by API changes bug help wanted

Comments

@Cugar15
Copy link

Cugar15 commented Jun 11, 2018

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.

  1. 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!

@tokiwinter
Copy link
Owner

tokiwinter commented Jun 18, 2018

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!

@tokiwinter tokiwinter added bug API Issues caused by API changes help wanted labels Jun 18, 2018
@Cugar15
Copy link
Author

Cugar15 commented Jun 21, 2018

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.

@tokiwinter
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Issues caused by API changes bug help wanted
Projects
None yet
Development

No branches or pull requests

2 participants