Files
ghost-docker/tinybird/getTokens.sh
Thomas Lamant fa605e91e7 fix(tinybird): use correct name for admin token (#83)
Fixes: #82

Updates the getTokens.sh script to use the correct name "workspace admin token" when fetching the admin token from the Tinybird API.

The script was previously using "admin token" which does not correspond to any token returned by the API, causing it to fail when extracting the admin token from the API response. This change ensures the correct token is identified and output for the user.
2025-11-04 13:16:03 -06:00

41 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Get token from .tinyb JSON file
USER_TOKEN=$(jq -r '.token' .tinyb)
if [ -z "$USER_TOKEN" ] || [ "$USER_TOKEN" = "null" ]; then
echo "Error: Could not find token in .tinyb file"
exit 1
fi
# Get host from .tinyb JSON file
HOST=$(jq -r '.host' .tinyb)
echo "TINYBIRD_API_URL=$HOST"
if [ -z "$HOST" ] || [ "$HOST" = "null" ]; then
echo "Error: Could not find host in .tinyb file"
exit 1
fi
# Get id from .tinyb JSON file
WORKSPACE_ID=$(jq -r '.id' .tinyb)
echo "TINYBIRD_WORKSPACE_ID=$WORKSPACE_ID"
if [ -z "$WORKSPACE_ID" ] || [ "$WORKSPACE_ID" = "null" ]; then
echo "Error: Could not find id in .tinyb file"
exit 1
fi
# Make GET request to tokens endpoint and parse response
RESPONSE=$(curl -s -X GET \
"$HOST/v0/tokens" \
-H "Authorization: Bearer $USER_TOKEN")
# Parse tokens from response
ADMIN_TOKEN=$(echo "$RESPONSE" | jq -r '.tokens[] | select(.name == "workspace admin token") | .token')
TRACKER_TOKEN=$(echo "$RESPONSE" | jq -r '.tokens[] | select(.name == "tracker") | .token')
# Echo the tokens as proof of concept
echo "TINYBIRD_ADMIN_TOKEN=$ADMIN_TOKEN"
echo "TINYBIRD_TRACKER_TOKEN=$TRACKER_TOKEN"