From 04a760f0ef7f894a14b8e10e16dbddf782a34401 Mon Sep 17 00:00:00 2001 From: Tim Kimber Date: Wed, 26 Nov 2025 17:19:58 +0000 Subject: [PATCH] Simplify dns_add_acmedns --- dns_scripts/dns_add_acmedns | 41 +++++++++---------------------------- test/run-test.sh | 19 ++++++++--------- 2 files changed, 18 insertions(+), 42 deletions(-) diff --git a/dns_scripts/dns_add_acmedns b/dns_scripts/dns_add_acmedns index b869ed5..eae8ecc 100755 --- a/dns_scripts/dns_add_acmedns +++ b/dns_scripts/dns_add_acmedns @@ -1,10 +1,5 @@ #!/usr/bin/env bash -. "$(dirname "${BASH_SOURCE}")/../common.shrc" || { - echo "Unable to load shared Bash code" - exit 1 -} >&2 - # ACMEDNS env variables can be set in a config file at domain level acme_config="$DOMAIN_DIR/acme-dns.cfg" [ -s "$acme_config" ] && . "$acme_config" @@ -37,29 +32,13 @@ if [[ -z "$token" ]]; then exit 1 fi -curl_params=( - -H "accept: application/json" - -H "X-Api-Key: $apikey" - -H "X-Api-User: $apiuser" - -H 'Content-Type: application/json' -) - -generate_post_data() -{ - cat </dev/null || { - echo 'Error: DNS challenge not added: unknown error' - exit 1 -} >&2 -exit 0 +curl --fail --silent -X POST "${API}" \ + -H "accept: application/json" \ + -H "X-Api-Key: $apikey" \ + -H "X-Api-User: $apiuser" \ + -H 'Content-Type: application/json' \ + -d '{ + "subdomain": "'"${apisubdomain}"'", + "txt": "'"$token"'" + }' + diff --git a/test/run-test.sh b/test/run-test.sh index d310ada..f6a7fed 100755 --- a/test/run-test.sh +++ b/test/run-test.sh @@ -1,27 +1,25 @@ #! /usr/bin/env bash +set -e + function add-dynu-domain() { domain=$1 - curl --fail -X POST "https://api.dynu.com/v2/dns" \ + curl --silent --fail-with-body -X POST "https://api.dynu.com/v2/dns" \ -H "accept: application/json" \ -H "API-Key: $DYNU_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "'"${domain}"'", - "group": "", "ipv4Address": "1.2.3.4", - "ipv6Address": "", - "ttl": 30, + "ttl": 60, "ipv4": true, - "ipv6": false, - "ipv4WildcardAlias": false, - "ipv6WildcardAlias": false + "ipv6": false }' } function get-dynu-domain-id() { domain=$1 - curl --fail -s -X GET "https://api.dynu.com/v2/dns" \ + curl --silent --fail-with-body -X GET "https://api.dynu.com/v2/dns" \ -H "accept: application/json" \ -H "API-Key: $DYNU_API_KEY" | \ jq -r ".domains[] | select(.name == \"${domain}\") | .id" @@ -33,7 +31,7 @@ function remove-dynu-domain() { domain_id=$(get-dynu-domain-id "$domain") echo "Found id for dynu domain: $domain = $domain_id" if [ -n "$domain_id" ] && [ "$domain_id" != "null" ]; then - curl --fail -X DELETE "https://api.dynu.com/v2/dns/${domain_id}" \ + curl --silent --fail-with-body -X DELETE "https://api.dynu.com/v2/dns/${domain_id}" \ -H "accept: application/json" \ -H "API-Key: $DYNU_API_KEY" echo "Domain $domain removed successfully" @@ -49,7 +47,7 @@ function add-dynu-cname() { echo "Creating CNAME record: ${subdomain}.${domain} -> ${target}" domain_id=$(get-dynu-domain-id "$domain") if [ -n "$domain_id" ] && [ "$domain_id" != "null" ]; then - curl --fail -X POST "https://api.dynu.com/v2/dns/${domain_id}/record" \ + curl --silent --fail-with-body -X POST "https://api.dynu.com/v2/dns/${domain_id}/record" \ -H "accept: application/json" \ -H "API-Key: $DYNU_API_KEY" \ -H "Content-Type: application/json" \ @@ -59,7 +57,6 @@ function add-dynu-cname() { "state": true, "host": "'"${target}"'" }' - echo "CNAME record created successfully" else echo "Error: Domain $domain not found" return 1