123 lines
3.6 KiB
Bash
Executable File
123 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Windmill REST API ヘルパースクリプト
|
|
# Usage: ./wm-api.sh <command> [args...]
|
|
|
|
set -euo pipefail
|
|
|
|
# 設定
|
|
WINDMILL_URL="${WINDMILL_URL:-https://windmill.keinafarm.net}"
|
|
WINDMILL_TOKEN="${WINDMILL_TOKEN:-qLJ3VPZ61kTDiIwaUPUu1dXszGrsN1Dh}"
|
|
WINDMILL_WORKSPACE="${WINDMILL_WORKSPACE:-admins}"
|
|
|
|
API_BASE="${WINDMILL_URL}/api/w/${WINDMILL_WORKSPACE}"
|
|
AUTH_HEADER="Authorization: Bearer ${WINDMILL_TOKEN}"
|
|
|
|
# ヘルパー関数
|
|
api_get() {
|
|
curl -sk -H "${AUTH_HEADER}" "${API_BASE}$1" 2>/dev/null
|
|
}
|
|
|
|
api_post() {
|
|
curl -sk -X POST -H "${AUTH_HEADER}" -H "Content-Type: application/json" -d "$2" "${API_BASE}$1" 2>/dev/null
|
|
}
|
|
|
|
api_put() {
|
|
curl -sk -X PUT -H "${AUTH_HEADER}" -H "Content-Type: application/json" -d "$2" "${API_BASE}$1" 2>/dev/null
|
|
}
|
|
|
|
api_delete() {
|
|
curl -sk -X DELETE -H "${AUTH_HEADER}" "${API_BASE}$1" 2>/dev/null
|
|
}
|
|
|
|
# コマンド
|
|
case "${1:-help}" in
|
|
whoami)
|
|
api_get "/users/whoami" | python3 -m json.tool
|
|
;;
|
|
scripts|list-scripts)
|
|
api_get "/scripts/list?per_page=${2:-100}" | python3 -m json.tool
|
|
;;
|
|
flows|list-flows)
|
|
api_get "/flows/list?per_page=${2:-100}" | python3 -m json.tool
|
|
;;
|
|
get-script)
|
|
if [ -z "${2:-}" ]; then
|
|
echo "Usage: $0 get-script <path>"
|
|
exit 1
|
|
fi
|
|
api_get "/scripts/get/p/$2" | python3 -m json.tool
|
|
;;
|
|
get-flow)
|
|
if [ -z "${2:-}" ]; then
|
|
echo "Usage: $0 get-flow <path>"
|
|
exit 1
|
|
fi
|
|
api_get "/flows/get/$2" | python3 -m json.tool
|
|
;;
|
|
create-script)
|
|
if [ -z "${2:-}" ]; then
|
|
echo "Usage: $0 create-script <json-file>"
|
|
exit 1
|
|
fi
|
|
api_post "/scripts/create" "$(cat "$2")"
|
|
;;
|
|
run-script)
|
|
if [ -z "${2:-}" ]; then
|
|
echo "Usage: $0 run-script <path> [json-args]"
|
|
exit 1
|
|
fi
|
|
local_args="${3:-{\}}"
|
|
api_post "/jobs/run/p/$2" "${local_args}"
|
|
;;
|
|
run-flow)
|
|
if [ -z "${2:-}" ]; then
|
|
echo "Usage: $0 run-flow <path> [json-args]"
|
|
exit 1
|
|
fi
|
|
local_args="${3:-{\}}"
|
|
api_post "/jobs/run/f/$2" "${local_args}"
|
|
;;
|
|
job-status)
|
|
if [ -z "${2:-}" ]; then
|
|
echo "Usage: $0 job-status <job-id>"
|
|
exit 1
|
|
fi
|
|
api_get "/jobs_u/get/$2" | python3 -m json.tool
|
|
;;
|
|
job-result)
|
|
if [ -z "${2:-}" ]; then
|
|
echo "Usage: $0 job-result <job-id>"
|
|
exit 1
|
|
fi
|
|
api_get "/jobs_u/completed/get_result/$2" | python3 -m json.tool
|
|
;;
|
|
schedules|list-schedules)
|
|
api_get "/schedules/list?per_page=${2:-100}" | python3 -m json.tool
|
|
;;
|
|
version)
|
|
curl -sk "${WINDMILL_URL}/api/version" 2>/dev/null
|
|
echo ""
|
|
;;
|
|
help|*)
|
|
cat << 'EOF'
|
|
Windmill REST API ヘルパー
|
|
|
|
使い方: ./wm-api.sh <command> [args...]
|
|
|
|
コマンド:
|
|
whoami - 現在のユーザー情報を表示
|
|
version - サーバーバージョンを表示
|
|
scripts - スクリプト一覧を表示
|
|
flows - フロー一覧を表示
|
|
get-script <path> - スクリプトの詳細を取得
|
|
get-flow <path> - フローの詳細を取得
|
|
create-script <file> - JSONファイルからスクリプトを作成
|
|
run-script <path> [args] - スクリプトを実行
|
|
run-flow <path> [args] - フローを実行
|
|
job-status <id> - ジョブのステータスを確認
|
|
job-result <id> - ジョブの結果を取得
|
|
schedules - スケジュール一覧を表示
|
|
EOF
|
|
;;
|
|
esac
|