Browse Source

Add error handling for Hetzner DNS scripts

pull/838/head
Lukas Kaufmann 2 years ago
parent
commit
5a96a01edf
2 changed files with 27 additions and 15 deletions
  1. +12
    -10
      dns_scripts/dns_add_hetzner
  2. +15
    -5
      dns_scripts/dns_del_hetzner

+ 12
- 10
dns_scripts/dns_add_hetzner View File

@ -28,21 +28,23 @@ fi
# Get Zone ID if not set
if [ -z "$HETZNER_ZONE_ID" ] ; then
zone_id=$(curl --silent -X GET "$api_url/zones?name=$HETZNER_ZONE_NAME" -H 'Auth-API-Token: '"$api_key"'' | jq -r '.zones[0].id')
if [ -z "$zone_id" == "null" ] ; then
echo "Zone ID not found"
exit 1
fi
fi
# domain_root=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF FS}')
# domain=${fulldomain%.$domain_root}
txtname="_acme-challenge.$fulldomain."
echo $zone_id
# Create TXT record
response=$(curl --silent -X POST "$api_url/records" \
-H 'Content-Type: application/json' \
-H "Auth-API-Token: $api_key" \
-d '{"value": "'$token'","ttl": 60,"type": "TXT","name": "_acme-challenge.'$fulldomain'.","zone_id": "'$zone_id'"}')
echo "$response"
# errors=$(echo "$response" | egrep -o "\"ERRORARRAY\":\[.*\]")
# if [[ $errors != "\"ERRORARRAY\":[]" ]]; then
# echo "Something went wrong: $errors"
# exit 1
# fi
-d '{"value": "'$token'","ttl": 60,"type": "TXT","name": "_acme-challenge.'$fulldomain'.","zone_id": "'$zone_id'"}' \
-o /dev/null -w '%{http_code}')
if [ "$response" != "200" ] ; then
echo "Record not created"
echo "Response code: $response"
exit 1
fi

+ 15
- 5
dns_scripts/dns_del_hetzner View File

@ -28,6 +28,10 @@ fi
# Get Zone ID if not set
if [ -z "$HETZNER_ZONE_ID" ] ; then
zone_id=$(curl --silent -X GET "$api_url/zones?name=$HETZNER_ZONE_NAME" -H 'Auth-API-Token: '"$api_key"'' | jq -r '.zones[0].id')
if [ "$zone_id" == "null" ] ; then
echo "Zone by name not found"
exit 1
fi
fi
# domain_root=$(echo "$fulldomain" | awk -F\. '{print $(NF-1) FS $NF FS}')
@ -37,11 +41,17 @@ txtname="_acme-challenge.$fulldomain."
record_id=$(curl --silent -X GET "$api_url/records?zone_id=$zone_id" -H "Auth-API-Token: $api_key" | jq -r '.records[] | select(.name=="'$txtname'") | .id')
if [ "$record_id" == "null" ] ; then
echo "Record not found"
exit 1
fi
# Create TXT record
response=$(curl --silent -X DELETE "$api_url/records/$record_id" -H "Auth-API-Token: $api_key")
response=$(curl --silent -X DELETE "$api_url/records/$record_id" -H "Auth-API-Token: $api_key" -o /dev/null -w '%{http_code}')
# errors=$(echo "$response" | egrep -o "\"ERRORARRAY\":\[.*\]")
if [[ $response != "\"ERRORARRAY\":[]" ]]; then
echo "Something went wrong: $errors"
exit 1
if [ "$response" != "200" ] ; then
echo "Record not deleted"
echo "Response code: $response"
exit 1
fi

Loading…
Cancel
Save