This commit is contained in:
Oliver
2025-08-16 07:37:53 +02:00
parent 140a712abf
commit c18187f407
11 changed files with 615 additions and 92 deletions

233
app/test/api.json Normal file
View File

@@ -0,0 +1,233 @@
{
"openapi": "3.0.0",
"info": {
"title": "Container Management API",
"version": "0.0.5",
"description": "API for managing containers and system resources."
},
"servers": [
{ "url": "http://localhost:8888" }
],
"components": {
"securitySchemes": {
"ApiKeyAuth": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key"
}
},
"schemas": {
"ContainerModel": {
"type": "object",
"properties": {
"UUID": { "type": "string" },
"email": { "type": "string" },
"expires": { "type": "string", "format": "date" },
"tags": { "type": "string" },
"env": { "type": "string" },
"affiliate": { "type": "string" },
"image": { "type": "string" },
"history": { "type": "string" },
"comment": { "type": "string" },
"domains": { "type": "string" },
"status": { "type": "string" },
"created": { "type": "string", "format": "date" },
"bump": { "type": "string", "format": "date" }
},
"required": ["UUID", "email", "expires", "status", "created"]
},
"ContainerIDRequest": {
"type": "object",
"properties": {
"container_id": { "type": "string" }
},
"required": ["container_id"]
},
"InfoContainerRequest": {
"type": "object",
"properties": {
"container_id": { "type": "string" }
}
}
}
},
"security": [{ "ApiKeyAuth": [] }],
"paths": {
"/": {
"get": {
"summary": "Root redirect",
"responses": {
"302": { "description": "Redirect to ODOO4PROJECTS.com" }
}
}
},
"/container/update": {
"post": {
"summary": "Create or update container",
"security": [{ "ApiKeyAuth": [] }],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ContainerModel" }
}
}
},
"responses": {
"200": {
"description": "Container updated or created",
"content": { "application/json": { "example": { "message": "Container updated or created" } } }
}
}
}
},
"/container/start": {
"post": {
"summary": "Start a container",
"security": [{ "ApiKeyAuth": [] }],
"requestBody": {
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContainerIDRequest" } } }
},
"responses": { "200": { "description": "Container started" } }
}
},
"/container/stop": {
"post": {
"summary": "Stop a container",
"security": [{ "ApiKeyAuth": [] }],
"requestBody": {
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContainerIDRequest" } } }
},
"responses": { "200": { "description": "Container stopped" } }
}
},
"/container/nuke": {
"post": {
"summary": "Nuke a container",
"description": "Permanently deletes container if its status is 'nuke'.",
"security": [{ "ApiKeyAuth": [] }],
"requestBody": {
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContainerIDRequest" } } }
},
"responses": {
"200": { "description": "Container nuked" },
"400": { "description": "Container status is not 'nuke'" }
}
}
},
"/container/info": {
"post": {
"summary": "Get container info",
"security": [{ "ApiKeyAuth": [] }],
"requestBody": {
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/InfoContainerRequest" } } }
},
"responses": { "200": { "description": "Container info list" } }
}
},
"/container/bump": {
"post": {
"summary": "Bump a container",
"description": "Updates bump date and runs bump script.",
"security": [{ "ApiKeyAuth": [] }],
"requestBody": {
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContainerIDRequest" } } }
},
"responses": {
"200": { "description": "Bump successful", "content": { "application/json": {} } }
}
}
},
"/container/quota": {
"post": {
"summary": "Get container quota",
"security": [{ "ApiKeyAuth": [] }],
"requestBody": {
"content": { "application/json": { "schema": { "$ref": "#/components/schemas/ContainerIDRequest" } } }
},
"responses": {
"200": {
"description": "Quota usage",
"content": {
"application/json": {
"example": {
"memory_usage": "50MiB / 2GiB",
"disk_io": "10MB / 200MB"
}
}
}
}
}
}
},
"/system/containers": {
"get": {
"summary": "List running containers",
"security": [{ "ApiKeyAuth": [] }],
"responses": {
"200": {
"description": "Containers in system",
"content": { "application/json": {} }
}
}
}
},
"/system/images": {
"get": {
"summary": "List system images",
"security": [{ "ApiKeyAuth": [] }],
"responses": {
"200": {
"description": "List of docker images",
"content": {
"application/json": {
"example": {
"images": ["repo1:tag", "repo2:tag"]
}
}
}
}
}
}
},
"/system/info": {
"get": {
"summary": "Get system info",
"security": [{ "ApiKeyAuth": [] }],
"responses": {
"200": {
"description": "System resource info",
"content": {
"application/json": {
"example": {
"alpine_version": "3.18.2",
"last_update": "2025-08-01",
"latest_bump": "2025-08-10",
"version": "API: 0.0.5",
"resources": {
"memory": { "total": 16777216, "available": 8388608, "used": 8388608 },
"disk": { "total": 100000000, "used": 50000000, "free": 50000000 },
"cpu_count": 8
}
}
}
}
}
}
}
},
"/system/pull": {
"post": {
"summary": "Pull all images",
"security": [{ "ApiKeyAuth": [] }],
"responses": {
"200": {
"description": "All images pulled",
"content": { "application/json": { "example": { "message": "All images pulled" } } }
}
}
}
}
}
}

View File

@@ -1,8 +0,0 @@
write a curl request that creatrs a container with
a uuid starting with 000-001-....
email o.arnold@projektbox.de
domain n8n.local
and the rest with sane info

53
app/test/runner.sh Normal file
View File

@@ -0,0 +1,53 @@
#!/bin/bash
#
# run_all_tests.sh — simple runner for test_api.sh
#
API_SCRIPT="./test_api.sh"
# Make sure test_api.sh is executable
if [ ! -x "$API_SCRIPT" ]; then
echo "Error: $API_SCRIPT not found or not executable"
exit 1
fi
# List of tests to run (must match functions in test_api.sh)
TESTS=(
root_redirect
update_container
start_container
stop_container
nuke_container
info_all
info_one
bump_container
container_quota
system_containers
system_images
system_info
system_pull
)
ok_count=0
fail_count=0
echo "Running API tests..."
echo "===================="
for test in "${TESTS[@]}"; do
# Run test, capture HTTP status code only
status=$($API_SCRIPT $test -s -o /dev/null -w "%{http_code}")
if [[ "$status" == "200" || "$status" == "302" ]]; then
echo "[OK ] $test"
((ok_count++))
else
echo "[NOK] $test (HTTP $status)"
((fail_count++))
fi
done
echo "===================="
echo "Summary: $ok_count OK, $fail_count NOK"
exit $fail_count

View File

@@ -1,5 +0,0 @@
start the container
000-001-
add a random uuid

141
app/test/test.sh Normal file
View File

@@ -0,0 +1,141 @@
#!/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 <<EOF
Usage: $0 <command>
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