brianreumere / gandi-automatic-dns

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

check access denied by Gandi #39

Closed cyayon closed 9 months ago

cyayon commented 9 months ago

I purpose to check Gandi response access denied. In case on bad API key or token, Gandi answer with 403 json.

Without this modification, gad script will try to create a new record.

update() create()

            new_record_message=$(get_json_field "message" "$new_record_json")
            if echo "$new_record_json" | grep -iE ":403,|access was denied|httpforbidden" >/dev/null 2>&1 ; then
                printf "Sorry, access was denied by gandi.\\n"
                printf "new_record_json:\\n---\\n%s\\n---\\n\\n" "$new_record_json"
                exit 9
            fi

check()

            record_json=$(rest "GET" "domains/${domain}/records/${1}/${record_type}")
            if echo "$record_json" | grep -iE ":403,|access was denied|httpforbidden" >/dev/null 2>&1 ; then
                printf "Sorry, access was denied by gandi.\\n"
                printf "record_json:\\n---\\n%s\\n---\\n\\n" "$record_json"
                exit 9
            fi

thanks

brianreumere commented 9 months ago

I like this idea. I'll add some basic error checking to the rest() function that will check for an error code in the response.

brianreumere commented 9 months ago

I added checking for 403 and 401 errors in v2.2.0.