Compare commits

..

No commits in common. "fix-curl-http-error-retries" and "main" have entirely different histories.

View file

@ -72,8 +72,6 @@ fi
PORKBUN_API_URL="https://api-ipv4.porkbun.com/api/json/v3" PORKBUN_API_URL="https://api-ipv4.porkbun.com/api/json/v3"
NOTES_PREFIX="ddns:" NOTES_PREFIX="ddns:"
# Fail on transient HTTP error bodies so retries cannot append HTML to JSON output.
CURL_RETRY_ARGS=(--silent --show-error --fail --retry 3 --retry-delay 2)
# Optional dry-run mode. When DRY_RUN=1, destructive or mutating API calls # Optional dry-run mode. When DRY_RUN=1, destructive or mutating API calls
# (dns/create, dns/delete) are logged but not executed. # (dns/create, dns/delete) are logged but not executed.
@ -101,7 +99,7 @@ function get_public_ip() {
fi fi
local ping_response local ping_response
ping_response=$(curl "${CURL_RETRY_ARGS[@]}" --max-time 10 -X POST "$PORKBUN_API_URL/ping" \ ping_response=$(curl -s --max-time 10 --retry 2 -X POST "$PORKBUN_API_URL/ping" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$auth_json" 2>&1 || echo "") -d "$auth_json" 2>&1 || echo "")
@ -114,14 +112,14 @@ function get_public_ip() {
# Fallback methods if Porkbun ping fails # Fallback methods if Porkbun ping fails
if [ -z "$ip" ]; then if [ -z "$ip" ]; then
ip=$(curl "${CURL_RETRY_ARGS[@]}" --max-time 5 https://api.ipify.org 2>/dev/null || echo "") ip=$(curl -s --max-time 5 --retry 2 https://api.ipify.org 2>/dev/null || echo "")
if [ -n "$ip" ]; then if [ -n "$ip" ]; then
printf '%s [INFO] IP source: api.ipify.org\n' "$(date)" >&2 printf '%s [INFO] IP source: api.ipify.org\n' "$(date)" >&2
fi fi
fi fi
if [ -z "$ip" ]; then if [ -z "$ip" ]; then
ip=$(curl "${CURL_RETRY_ARGS[@]}" --max-time 5 https://icanhazip.com 2>/dev/null || echo "") ip=$(curl -s --max-time 5 --retry 2 https://icanhazip.com 2>/dev/null || echo "")
if [ -n "$ip" ]; then if [ -n "$ip" ]; then
printf '%s [INFO] IP source: icanhazip.com\n' "$(date)" >&2 printf '%s [INFO] IP source: icanhazip.com\n' "$(date)" >&2
fi fi
@ -180,7 +178,7 @@ function register_host_dns() {
# Retrieve all DNS records for the domain # Retrieve all DNS records for the domain
local records local records
if ! records=$(curl "${CURL_RETRY_ARGS[@]}" --max-time 10 -X POST "$PORKBUN_API_URL/dns/retrieve/$domain" \ if ! records=$(curl -s --max-time 10 --retry 2 -X POST "$PORKBUN_API_URL/dns/retrieve/$domain" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$auth_json" 2>&1); then -d "$auth_json" 2>&1); then
printf '%s [ERROR] Failed to retrieve DNS records: %s\n' "$(date)" "$records" >&2 printf '%s [ERROR] Failed to retrieve DNS records: %s\n' "$(date)" "$records" >&2
@ -252,7 +250,7 @@ function register_host_dns() {
if [ "$DRY_RUN" -eq 1 ]; then if [ "$DRY_RUN" -eq 1 ]; then
printf "%s [INFO] DRY RUN: Skipping actual delete for record ID %s\n" "$(date)" "$record_id" printf "%s [INFO] DRY RUN: Skipping actual delete for record ID %s\n" "$(date)" "$record_id"
else else
if curl "${CURL_RETRY_ARGS[@]}" --max-time 10 -X POST "$PORKBUN_API_URL/dns/delete/$domain/$record_id" \ if curl -s --max-time 10 --retry 2 -X POST "$PORKBUN_API_URL/dns/delete/$domain/$record_id" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$auth_json" > /dev/null 2>&1; then -d "$auth_json" > /dev/null 2>&1; then
((delete_count++)) || true ((delete_count++)) || true
@ -269,7 +267,7 @@ function register_host_dns() {
# Verify no duplicates remain before creating new record # Verify no duplicates remain before creating new record
# Re-fetch records to ensure we have latest state # Re-fetch records to ensure we have latest state
if ! records=$(curl "${CURL_RETRY_ARGS[@]}" --max-time 10 -X POST "$PORKBUN_API_URL/dns/retrieve/$domain" \ if ! records=$(curl -s --max-time 10 --retry 2 -X POST "$PORKBUN_API_URL/dns/retrieve/$domain" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$auth_json" 2>&1); then -d "$auth_json" 2>&1); then
printf '%s [WARN] Failed to re-verify DNS records after deletion: %s\n' "$(date)" "$records" >&2 printf '%s [WARN] Failed to re-verify DNS records after deletion: %s\n' "$(date)" "$records" >&2
@ -309,7 +307,7 @@ function register_host_dns() {
fi fi
local create_response local create_response
if ! create_response=$(curl "${CURL_RETRY_ARGS[@]}" --max-time 10 -X POST "$PORKBUN_API_URL/dns/create/$domain" \ if ! create_response=$(curl -s --max-time 10 --retry 2 -X POST "$PORKBUN_API_URL/dns/create/$domain" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$create_json" 2>&1); then -d "$create_json" 2>&1); then
printf '%s [ERROR] Failed to create DNS record: %s\n' "$(date)" "$create_response" >&2 printf '%s [ERROR] Failed to create DNS record: %s\n' "$(date)" "$create_response" >&2
@ -322,7 +320,7 @@ function register_host_dns() {
printf "%s [INFO] Successfully created A record for %s (machine: %s)\n" "$(date)" "$fqdn" "$MACHINE_ID" printf "%s [INFO] Successfully created A record for %s (machine: %s)\n" "$(date)" "$fqdn" "$MACHINE_ID"
# Final verification: ensure exactly one record exists # Final verification: ensure exactly one record exists
if records=$(curl "${CURL_RETRY_ARGS[@]}" --max-time 10 -X POST "$PORKBUN_API_URL/dns/retrieve/$domain" \ if records=$(curl -s --max-time 10 --retry 2 -X POST "$PORKBUN_API_URL/dns/retrieve/$domain" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$auth_json" 2>&1); then -d "$auth_json" 2>&1); then
local final_count local final_count