Skip to content

Commit ff9e886

Browse files
cmraiblejloh
authored andcommitted
Added experimental script to automate fetching Tinybird tokens
1 parent 62ff213 commit ff9e886

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

tinybird/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ FROM python:3.13-slim@sha256:6544e0e002b40ae0f59bc3618b07c1e48064c4faed3a15ae2fb
33
# Install dependencies
44
RUN apt-get update && apt-get install -y --no-install-recommends \
55
curl \
6+
jq \
67
ca-certificates \
78
&& rm -rf /var/lib/apt/lists/*
89

910
WORKDIR /home/tinybird
1011

1112
# Install Tinybird using the standard installation script
1213
COPY handleLogin.sh /usr/local/bin/tinybird-login
14+
COPY getTokens.sh /usr/local/bin/get-tokens
1315
COPY tb-wrapper /usr/local/bin/tb-wrapper
1416

1517
RUN curl https://tinybird.co | sh

tinybird/getTokens.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Get token from .tinyb JSON file
4+
USER_TOKEN=$(jq -r '.token' .tinyb)
5+
echo "User token: $USER_TOKEN"
6+
7+
if [ -z "$USER_TOKEN" ] || [ "$USER_TOKEN" = "null" ]; then
8+
echo "Error: Could not find token in .tinyb file"
9+
exit 1
10+
fi
11+
12+
# Get host from .tinyb JSON file
13+
HOST=$(jq -r '.host' .tinyb)
14+
echo "Host: $HOST"
15+
16+
if [ -z "$HOST" ] || [ "$HOST" = "null" ]; then
17+
echo "Error: Could not find host in .tinyb file"
18+
exit 1
19+
fi
20+
21+
# Get id from .tinyb JSON file
22+
WORKSPACE_ID=$(jq -r '.id' .tinyb)
23+
echo "Workspace ID: $WORKSPACE_ID"
24+
25+
if [ -z "$WORKSPACE_ID" ] || [ "$WORKSPACE_ID" = "null" ]; then
26+
echo "Error: Could not find id in .tinyb file"
27+
exit 1
28+
fi
29+
30+
# Make GET request to tokens endpoint and parse response
31+
RESPONSE=$(curl -s -X GET \
32+
"$HOST/v0/tokens" \
33+
-H "Authorization: Bearer $USER_TOKEN")
34+
35+
# Parse tokens from response
36+
ADMIN_TOKEN=$(echo "$RESPONSE" | jq -r '.tokens[] | select(.name == "admin token") | .token')
37+
TRACKER_TOKEN=$(echo "$RESPONSE" | jq -r '.tokens[] | select(.name == "tracker") | .token')
38+
39+
# Echo the tokens as proof of concept
40+
echo "Admin token: $ADMIN_TOKEN"
41+
echo "Tracker token: $TRACKER_TOKEN"

0 commit comments

Comments
 (0)