feat: update init-channels to use cookie
This commit is contained in:
parent
8c872e3c35
commit
5356e0ac64
1 changed files with 7 additions and 7 deletions
|
|
@ -27,26 +27,26 @@ fi
|
|||
API_BASE="${NEW_API_BASE:-http://localhost:4000}"
|
||||
USERNAME="${NEW_API_USERNAME:-root}"
|
||||
PASSWORD="${NEW_API_PASSWORD:?Set NEW_API_PASSWORD to the admin password}"
|
||||
COOKIE_JAR=$(mktemp)
|
||||
trap 'rm -f "$COOKIE_JAR"' EXIT
|
||||
|
||||
# ── Login to get session token ──────────────────────────
|
||||
# ── Login to get session cookie ─────────────────────────
|
||||
login() {
|
||||
echo "Logging in as ${USERNAME}..."
|
||||
local resp
|
||||
resp=$(curl -s "${API_BASE}/api/user/login" \
|
||||
resp=$(curl -s -c "$COOKIE_JAR" "${API_BASE}/api/user/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(python3 -c "
|
||||
import json, sys
|
||||
print(json.dumps({'username': sys.argv[1], 'password': sys.argv[2]}))
|
||||
" "$USERNAME" "$PASSWORD")")
|
||||
|
||||
local success token
|
||||
local success
|
||||
success=$(echo "$resp" | python3 -c "import sys,json; print(json.load(sys.stdin).get('success', False))")
|
||||
if [[ "$success" != "True" ]]; then
|
||||
echo "ERROR: Login failed: ${resp}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TOKEN=$(echo "$resp" | python3 -c "import sys,json; print(json.load(sys.stdin)['data']['access_token'])")
|
||||
echo " Logged in."
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ print(json.dumps({
|
|||
|
||||
local resp success
|
||||
resp=$(curl -s "${API_BASE}/api/channel/" \
|
||||
-H "Authorization: Bearer ${TOKEN}" \
|
||||
-b "$COOKIE_JAR" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$payload")
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ create_channel "Cerebras" 1 \
|
|||
echo ""
|
||||
echo "Creating API token for Open WebUI..."
|
||||
TOKEN_RESP=$(curl -s "${API_BASE}/api/token/" \
|
||||
-H "Authorization: Bearer ${TOKEN}" \
|
||||
-b "$COOKIE_JAR" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(python3 -c "
|
||||
import json
|
||||
|
|
|
|||
Loading…
Reference in a new issue