mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
Added admin API script (#196)
This commit is contained in:
1 parent
ae85ec0a09
commit
2ee3cabc92
1 file changed
+41
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
# Admin API helper script
|
||||
# Usage: ./scripts/admin_api.sh <endpoint> [method] [data]
|
||||
#
|
||||
# Examples:
|
||||
# ./scripts/admin_api.sh /api/jobs # List all jobs (admin sees all)
|
||||
# ./scripts/admin_api.sh /api/jobs?limit=10 # List 10 jobs
|
||||
# ./scripts/admin_api.sh /api/jobs/abc123 # Get specific job
|
||||
# ./scripts/admin_api.sh /api/jobs/abc123/retry POST # Retry a job
|
||||
# ./scripts/admin_api.sh /api/jobs/abc123/select-instrumental POST '{"selection":"clean"}'
|
||||
|
||||
set -e
|
||||
|
||||
API_URL="${KARAOKE_API_URL:-https://api.nomadkaraoke.com}"
|
||||
|
||||
# Get admin token from Secret Manager if not set
|
||||
if [ -z "$KARAOKE_ADMIN_TOKEN" ]; then
|
||||
KARAOKE_ADMIN_TOKEN=$(gcloud secrets versions access latest --secret=admin-tokens --project=nomadkaraoke 2>/dev/null)
|
||||
fi
|
||||
|
||||
if [ -z "$KARAOKE_ADMIN_TOKEN" ]; then
|
||||
echo "Error: Could not get admin token. Run 'gcloud auth login' first." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ENDPOINT="${1:-/api/admin/jobs}"
|
||||
METHOD="${2:-GET}"
|
||||
DATA="$3"
|
||||
|
||||
if [ "$METHOD" = "GET" ]; then
|
||||
curl -s "${API_URL}${ENDPOINT}" \
|
||||
-H "Authorization: Bearer $KARAOKE_ADMIN_TOKEN" | jq .
|
||||
elif [ -n "$DATA" ]; then
|
||||
curl -s -X "$METHOD" "${API_URL}${ENDPOINT}" \
|
||||
-H "Authorization: Bearer $KARAOKE_ADMIN_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$DATA" | jq .
|
||||
else
|
||||
curl -s -X "$METHOD" "${API_URL}${ENDPOINT}" \
|
||||
-H "Authorization: Bearer $KARAOKE_ADMIN_TOKEN" | jq .
|
||||
fi
|
||||
Reference in new issue
Block a user