Fix Cloudflare API token handling

This commit is contained in:
Root User 2026-03-03 11:09:35 +01:00
parent c8c1e0ec22
commit 1f3594efa5
Signed by: root
GPG key ID: 087F0A95E5766D72

View file

@ -613,7 +613,7 @@ in {
source "${envFile}" source "${envFile}"
fi fi
if [ -z "$CLOUDFLARE_API_TOKEN" ]; then if [ -z "$${CLOUDFLARE_API_TOKEN:-}" ]; then
echo "CLOUDFLARE_API_TOKEN is not set in ${envFile}, aborting" >&2 echo "CLOUDFLARE_API_TOKEN is not set in ${envFile}, aborting" >&2
exit 2 exit 2
fi fi
@ -633,7 +633,7 @@ in {
local fqdn="$1" local fqdn="$1"
# Query existing A records for fqdn # Query existing A records for fqdn
res=$(curl -sS -X GET "$API_BASE/zones/${zoneId}/dns_records?type=A&name=$fqdn" \ res=$(curl -sS -X GET "$API_BASE/zones/${zoneId}/dns_records?type=A&name=$fqdn" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ -H "Authorization: Bearer $${CLOUDFLARE_API_TOKEN:-}" \
-H "Content-Type: application/json") -H "Content-Type: application/json")
ok=$(echo "$res" | $jq -r '.success') ok=$(echo "$res" | $jq -r '.success')
@ -658,13 +658,13 @@ in {
if [ -n "$record_id" ]; then if [ -n "$record_id" ]; then
echo "Updating $fqdn ($record_id) -> $CURRENT_IP" echo "Updating $fqdn ($record_id) -> $CURRENT_IP"
curl -sS -X PUT "$API_BASE/zones/${zoneId}/dns_records/$record_id" \ curl -sS -X PUT "$API_BASE/zones/${zoneId}/dns_records/$record_id" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ -H "Authorization: Bearer $${CLOUDFLARE_API_TOKEN:-}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
--data "$payload" | $jq -r '.' --data "$payload" | $jq -r '.'
else else
echo "Creating record $fqdn -> $CURRENT_IP" echo "Creating record $fqdn -> $CURRENT_IP"
curl -sS -X POST "$API_BASE/zones/${zoneId}/dns_records" \ curl -sS -X POST "$API_BASE/zones/${zoneId}/dns_records" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ -H "Authorization: Bearer $${CLOUDFLARE_API_TOKEN:-}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
--data "$payload" | $jq -r '.' --data "$payload" | $jq -r '.'
fi fi