brianreumere / gandi-automatic-dns

Dynamic DNS shell script for Gandi
Other
100 stars 22 forks source link

The script randomly fails #32

Closed nnn1590 closed 2 years ago

nnn1590 commented 2 years ago

Since Dec 23 2021, I get the error Sorry, but gad does not support updating multiple records with the same name. sometimes.

The order in the record_json seems to be random, and the script will fail if rrset_values is not at the end.

Successful attempt:

$ curl -s ipinfo.io/ip | gad -e -s -5 -i <interface> -d <DOMAIN> -r "@"
record_json:
---
{"rrset_type": "A", "rrset_ttl": 1800, "rrset_name": "@", "rrset_href": "https://dns.api.gandi.net/api/v5/zones/<UUID>/records/%40/A", "rrset_values": ["<IPv4ADDRESS>"]}
---

record_value:
---
<IPv4ADDRESS>
---

Failed attempt:

$ curl -s ipinfo.io/ip | gad -e -s -5 -i <interface> -d <DOMAIN> -r "@"
record_json:
---
{"rrset_name": "@", "rrset_type": "A", "rrset_ttl": 1800, "rrset_values": ["<IPv4ADDRESS>"], "rrset_href": "https://dns.api.gandi.net/api/v5/zones/<UUID>/records/@/A"}
---

record_value:
---
<IPv4ADDRESS> rrset_href
---

Sorry, but gad does not support updating multiple records with the same name.
Full log of failed attempt ```console $ curl -s ipinfo.io/ip | gad -e -s -5 -i -d -r "@" Initial variables: --- apikey = domain = records = @ ttl (only relevant with LiveDNS) = record_type = A ip_regex = \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\) --- IP information: --- ext_ip_method: standard input ext_ip: --- REST call to endpoint: --- domains/ --- Sending REST message tmp_message: --- GET /api/v5/domains/ HTTP/1.1 User-Agent: Gandi Automatic DNS shell script/1.4.2 Host: dns.api.gandi.net Content-Type: application/json Content-Length: 0 X-Api-Key: --- domain_json: --- {"fqdn": "", "domain_href": "https://dns.api.gandi.net/api/v5/domains/", "domain_records_href": "https://dns.api.gandi.net/api/v5/domains//records", "zone_uuid": "", "zone_href": "https://dns.api.gandi.net/api/v5/zones/", "zone_records_href": "https://dns.api.gandi.net/api/v5/zones//records", "domain_keys_href": "https://dns.api.gandi.net/api/v5/domains//keys", "automatic_snapshots": true} --- zone_id: --- --- REST call to endpoint: --- zones//records/@/A --- Sending REST message tmp_message: --- GET /api/v5/zones//records/@/A HTTP/1.1 User-Agent: Gandi Automatic DNS shell script/1.4.2 Host: dns.api.gandi.net Content-Type: application/json Content-Length: 0 X-Api-Key: --- record_json: --- {"rrset_name": "@", "rrset_type": "A", "rrset_ttl": 1800, "rrset_values": [""], "rrset_href": "https://dns.api.gandi.net/api/v5/zones//records/@/A"} --- Sorry, but gad does not support updating multiple records with the same name. ```
Patch to show record_value ```diff diff --git a/gad b/gad index 1b2c3e3..db524fd 100755 --- a/gad +++ b/gad @@ -310,6 +310,9 @@ check() { record_value=$(get_json_field "rrset_values" "$record_json") record_ttl=$(get_json_field "rrset_ttl" "$record_json") record_count=$(printf "%s" "$record_value" | wc -w) + if [ "$debug" = "yes" ]; then + printf "record_value:\\n---\\n%s\\n---\\n\\n" "$record_value" + fi # If a custom TTL wasn't provided, just set it to the existing one. # If the record TTL is empty (because the record doesn't exist) and # no custom TTL was provided, set a default. ```

I'm sorry if my english is wrong.

brianreumere commented 2 years ago

This looks like a bug in the get_json_field() function (it's returning "rrset_href" instead of just the record value). I'll start looking into this today. Thanks for reporting it! (And your English is fine!)

brianreumere commented 2 years ago

This should be fixed in the latest release (and in the master branch). Let me know if it works!

brianreumere commented 2 years ago

Oh, and if you're using standard input (-s) to provide your IP address, you can remove the -i <interface> part of the command (it will be ignored anyway since you specified -s). Just thought I'd mention it since I noticed it in your example commands.

nnn1590 commented 2 years ago

It works! Thank you!