#!/bin/bash # # test_api.sh — cURL test suite for Container Management API # # ========= CONFIG ========= API_KEY="your-secret-api-key" BASE_URL="http://localhost:8888" CONTAINER_ID="123e4567-e89b-12d3-a456-426614174000" # sample UUID # ========================== # --- Functions for each endpoint --- root_redirect() { curl -i "$BASE_URL/" } update_container() { curl -X POST "$BASE_URL/container/update" \ -H "Content-Type: application/json" \ -H "X-API-Key: $API_KEY" \ -d '{ "UUID": "'"$CONTAINER_ID"'", "email": "user@example.com", "expires": "2025-12-31", "status": "active", "created": "2025-08-16" }' } start_container() { curl -X POST "$BASE_URL/container/start" \ -H "Content-Type: application/json" \ -H "X-API-Key: $API_KEY" \ -d '{ "container_id": "'"$CONTAINER_ID"'" }' } stop_container() { curl -X POST "$BASE_URL/container/stop" \ -H "Content-Type: application/json" \ -H "X-API-Key: $API_KEY" \ -d '{ "container_id": "'"$CONTAINER_ID"'" }' } nuke_container() { curl -X POST "$BASE_URL/container/nuke" \ -H "Content-Type: application/json" \ -H "X-API-Key: $API_KEY" \ -d '{ "container_id": "'"$CONTAINER_ID"'" }' } info_all() { curl -X POST "$BASE_URL/container/info" \ -H "Content-Type: application/json" \ -H "X-API-Key: $API_KEY" \ -d '{}' } info_one() { curl -X POST "$BASE_URL/container/info" \ -H "Content-Type: application/json" \ -H "X-API-Key: $API_KEY" \ -d '{ "container_id": "'"$CONTAINER_ID"'" }' } bump_container() { curl -X POST "$BASE_URL/container/bump" \ -H "Content-Type: application/json" \ -H "X-API-Key: $API_KEY" \ -d '{ "container_id": "'"$CONTAINER_ID"'" }' } container_quota() { curl -X POST "$BASE_URL/container/quota" \ -H "Content-Type: application/json" \ -H "X-API-Key: $API_KEY" \ -d '{ "container_id": "'"$CONTAINER_ID"'" }' } system_containers() { curl -X GET "$BASE_URL/system/containers" \ -H "X-API-Key: $API_KEY" } system_images() { curl -X GET "$BASE_URL/system/images" \ -H "X-API-Key: $API_KEY" } system_info() { curl -X GET "$BASE_URL/system/info" \ -H "X-API-Key: $API_KEY" } system_pull() { curl -X POST "$BASE_URL/system/pull" \ -H "X-API-Key: $API_KEY" } # --- Help message --- show_help() { cat < Available commands: root_redirect - Test root redirect update_container - Create or update container start_container - Start container stop_container - Stop container nuke_container - Nuke container (status must be "nuke") info_all - Get info for all containers info_one - Get info for one container bump_container - Bump container container_quota - Show container quota system_containers - List running containers system_images - List docker images system_info - Show system information system_pull - Pull all container images Examples: $0 update_container $0 system_info EOF } # --- Main --- if [ $# -eq 0 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then show_help exit 0 fi cmd="$1" shift if declare -f "$cmd" >/dev/null 2>&1; then "$cmd" "$@" else echo "Unknown command: $cmd" show_help exit 1 fi