Skip to content

Commit 251d6d5

Browse files
committed
Separate auth token extraction from sources creation
1 parent 7c52a14 commit 251d6d5

3 files changed

Lines changed: 55 additions & 37 deletions

File tree

.github/scripts/create_and_format_sources.sh

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,20 @@
11
#!/bin/bash
22
set -e
33

4-
: "${RETRY_COUNT:?Need to set RETRY_COUNT}"
54
: "${DREMIO_HEALTH_URL:?Need to set DREMIO_HEALTH_URL}"
6-
: "${SLEEP_INTERVAL:?Need to set SLEEP_INTERVAL}"
7-
: "${DREMIO_SOFTWARE_USERNAME:?Need to set DREMIO_SOFTWARE_USERNAME}"
8-
: "${DREMIO_SOFTWARE_PASSWORD:?Need to set DREMIO_SOFTWARE_PASSWORD}"
95
: "${MINIO_ROOT_USER:?Need to set MINIO_ROOT_USER}"
106
: "${MINIO_ROOT_PASSWORD:?Need to set MINIO_ROOT_PASSWORD}"
117

12-
for i in $(seq 1 $RETRY_COUNT); do
13-
if curl -s $DREMIO_HEALTH_URL; then
14-
echo "Dremio is up."
15-
break
16-
fi
17-
echo "Waiting for Dremio to become ready... ($i/$RETRY_COUNT)"
18-
sleep $SLEEP_INTERVAL
19-
done
20-
21-
if ! curl -s $DREMIO_HEALTH_URL; then
22-
echo "Dremio did not become ready in time."
23-
exit 1
24-
fi
25-
26-
# Obtain Dremio auth token
27-
echo "Logging into Dremio to obtain auth token..."
28-
AUTH_RESPONSE=$(curl -s -X POST "$DREMIO_HEALTH_URL/apiv2/login" \
29-
-H "Content-Type: application/json" \
30-
--data "{\"userName\":\"${DREMIO_SOFTWARE_USERNAME}\", \"password\":\"${DREMIO_SOFTWARE_PASSWORD}\"}")
31-
32-
AUTH_TOKEN=$(echo "$AUTH_RESPONSE" | jq -r .token)
33-
34-
# Check if AUTH_TOKEN is not empty
35-
if [ -z "$AUTH_TOKEN" ] || [ "$AUTH_TOKEN" == "null" ]; then
36-
echo "Failed to obtain Dremio auth token."
37-
exit 1
38-
fi
39-
40-
echo "Obtained Dremio auth token."
41-
echo "::add-mask::$AUTH_TOKEN"
8+
# Get AUTH_TOKEN from environment or file
429
if [ "$GITHUB_ACTIONS" = "true" ]; then
43-
echo "Running in GitHub Actions"
44-
echo "AUTH_TOKEN=${AUTH_TOKEN}" >> $GITHUB_ENV
10+
: "${AUTH_TOKEN:?Need to set AUTH_TOKEN}"
4511
HOST="minio"
4612
else # Jenkins
47-
echo $AUTH_TOKEN > /tmp/auth_token.txt
13+
if [ ! -f /tmp/auth_token.txt ]; then
14+
echo "Auth token file not found. Please run extract_auth_token.sh first."
15+
exit 1
16+
fi
17+
AUTH_TOKEN=$(cat /tmp/auth_token.txt)
4818
HOST="localhost"
4919
fi
5020

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
set -e
3+
4+
: "${RETRY_COUNT:?Need to set RETRY_COUNT}"
5+
: "${DREMIO_HEALTH_URL:?Need to set DREMIO_HEALTH_URL}"
6+
: "${SLEEP_INTERVAL:?Need to set SLEEP_INTERVAL}"
7+
: "${DREMIO_SOFTWARE_USERNAME:?Need to set DREMIO_SOFTWARE_USERNAME}"
8+
: "${DREMIO_SOFTWARE_PASSWORD:?Need to set DREMIO_SOFTWARE_PASSWORD}"
9+
10+
for i in $(seq 1 $RETRY_COUNT); do
11+
if curl -s $DREMIO_HEALTH_URL; then
12+
echo "Dremio is up."
13+
break
14+
fi
15+
echo "Waiting for Dremio to become ready... ($i/$RETRY_COUNT)"
16+
sleep $SLEEP_INTERVAL
17+
done
18+
19+
if ! curl -s $DREMIO_HEALTH_URL; then
20+
echo "Dremio did not become ready in time."
21+
exit 1
22+
fi
23+
24+
# Obtain Dremio auth token
25+
echo "Logging into Dremio to obtain auth token..."
26+
AUTH_RESPONSE=$(curl -s -X POST "$DREMIO_HEALTH_URL/apiv2/login" \
27+
-H "Content-Type: application/json" \
28+
--data "{\"userName\":\"${DREMIO_SOFTWARE_USERNAME}\", \"password\":\"${DREMIO_SOFTWARE_PASSWORD}\"}")
29+
30+
AUTH_TOKEN=$(echo "$AUTH_RESPONSE" | jq -r .token)
31+
32+
# Check if AUTH_TOKEN is not empty
33+
if [ -z "$AUTH_TOKEN" ] || [ "$AUTH_TOKEN" == "null" ]; then
34+
echo "Failed to obtain Dremio auth token."
35+
exit 1
36+
fi
37+
38+
echo "Obtained Dremio auth token."
39+
echo "::add-mask::$AUTH_TOKEN"
40+
if [ "$GITHUB_ACTIONS" = "true" ]; then
41+
echo "Running in GitHub Actions"
42+
echo "AUTH_TOKEN=${AUTH_TOKEN}" >> $GITHUB_ENV
43+
else # Jenkins
44+
echo $AUTH_TOKEN > /tmp/auth_token.txt
45+
fi

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ jobs:
7575
- name: Create MinIO bucket
7676
run: bash .github/scripts/create_minio_bucket.sh
7777

78+
- name: Extract Auth Token
79+
run: bash .github/scripts/extract_auth_token.sh
80+
7881
- name: Create and Format Sources
7982
run: bash .github/scripts/create_and_format_sources.sh
8083

0 commit comments

Comments
 (0)