Skip to content

Commit b2dd3a2

Browse files
committed
fix: add token verification step to debug authentication issues
1 parent fdc0a63 commit b2dd3a2

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

.github/workflows/test_cloudflare_purge.yml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,43 @@ jobs:
1818
echo "Commit: ${{ github.sha }}"
1919
echo "Host: polygon-docs.polygon.technology"
2020
21+
- name: Verify Cloudflare Token
22+
run: |
23+
ZONE_ID=$(echo "${{ secrets.CLOUDFLARE_ZONE }}" | tr -d '[:space:]')
24+
AUTH_TOKEN=$(echo "${{ secrets.CLOUDFLARE_AUTH_KEY }}" | tr -d '[:space:]')
25+
26+
echo "Zone ID length: ${#ZONE_ID}"
27+
echo "Token length: ${#AUTH_TOKEN}"
28+
echo "Token preview: ${AUTH_TOKEN:0:10}...${AUTH_TOKEN: -5}"
29+
30+
echo "Testing token by fetching zone info..."
31+
VERIFY_RESPONSE=$(curl -s -w "\n%{http_code}" -X GET \
32+
"https://api.cloudflare.com/client/v4/zones/${ZONE_ID}" \
33+
-H "Authorization: Bearer ${AUTH_TOKEN}" \
34+
-H "Content-Type: application/json")
35+
36+
VERIFY_HTTP_CODE=$(echo "$VERIFY_RESPONSE" | tail -n1)
37+
VERIFY_BODY=$(echo "$VERIFY_RESPONSE" | sed '$d')
38+
39+
echo "Verify HTTP Status: $VERIFY_HTTP_CODE"
40+
if [ "$VERIFY_HTTP_CODE" -ne 200 ]; then
41+
echo "❌ Token verification failed!"
42+
echo "$VERIFY_BODY" | jq '.' || echo "$VERIFY_BODY"
43+
echo ""
44+
echo "Common issues:"
45+
echo "1. Token may be invalid or expired"
46+
echo "2. Token may not have 'Zone.Read' permission"
47+
echo "3. Zone ID may be incorrect"
48+
exit 1
49+
else
50+
ZONE_NAME=$(echo "$VERIFY_BODY" | jq -r '.result.name' 2>/dev/null || echo "unknown")
51+
echo "✅ Token verified! Zone: $ZONE_NAME"
52+
echo "ZONE_ID=${ZONE_ID}" >> $GITHUB_ENV
53+
echo "AUTH_TOKEN=${AUTH_TOKEN}" >> $GITHUB_ENV
54+
fi
55+
2156
- name: Cloudflare Cache Purge
2257
run: |
23-
ZONE_ID="${{ secrets.CLOUDFLARE_ZONE }}"
24-
AUTH_TOKEN="${{ secrets.CLOUDFLARE_AUTH_KEY }}"
2558
HOST="polygon-docs.polygon.technology"
2659
2760
echo "Purging cache for host: $HOST"
@@ -51,6 +84,13 @@ jobs:
5184
fi
5285
else
5386
echo "❌ HTTP request failed with status $HTTP_CODE"
87+
if [ "$HTTP_CODE" -eq 401 ]; then
88+
echo ""
89+
echo "Authentication failed. Please verify:"
90+
echo "1. The API token is valid and not expired"
91+
echo "2. The token has 'Zone.Cache Purge' permission"
92+
echo "3. The token is for the correct Cloudflare account"
93+
fi
5494
exit 1
5595
fi
5696

0 commit comments

Comments
 (0)