-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTEST_API_KEY_GENERATION.sh
More file actions
executable file
·80 lines (76 loc) · 2.72 KB
/
TEST_API_KEY_GENERATION.sh
File metadata and controls
executable file
·80 lines (76 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Test API Key Generation via Admin Endpoint
# This script tests the new API key authentication system
echo "=========================================="
echo "API KEY GENERATION TEST"
echo "=========================================="
echo ""
# Step 1: Generate API key (requires admin session - run from authenticated browser)
echo "Step 1: Generate API key via admin endpoint"
echo ""
echo "Run this in your browser console (while logged in as admin):"
echo ""
echo "fetch('http://localhost:8084/api/v1/admin/users/admin@example.com/api-keys', {"
echo " method: 'POST',"
echo " headers: { 'Content-Type': 'application/json' },"
echo " body: JSON.stringify({"
echo " name: 'My First API Key',"
echo " expires_in_days: 90,"
echo " permissions: ['llm:inference', 'llm:models']"
echo " })"
echo "}).then(r => r.json()).then(console.log)"
echo ""
echo "=========================================="
echo ""
# Step 2: Test with API key
echo "Step 2: After getting your API key, test it with:"
echo ""
echo "API_KEY='uc_YOUR_KEY_HERE'"
echo ""
echo "# Test models endpoint (no auth required)"
echo "curl http://localhost:8084/api/v1/llm/models | jq '.data[:3]'"
echo ""
echo "# Test chat completions (requires API key)"
echo "curl -X POST http://localhost:8084/api/v1/llm/chat/completions \\"
echo " -H 'Authorization: Bearer \$API_KEY' \\"
echo " -H 'Content-Type: application/json' \\"
echo " -d '{"
echo " \"model\": \"openai/gpt-4o-mini\","
echo " \"messages\": [{\"role\": \"user\", \"content\": \"Hello!\"}]"
echo " }' | jq '.'"
echo ""
echo "=========================================="
echo ""
# Alternative: Direct database method for testing
echo "Alternative: Generate API key directly via database"
echo ""
echo "# Run this in Python (in container):"
echo "docker exec -it ops-center-direct python3 << 'PYTHON'"
echo "import asyncio"
echo "import asyncpg"
echo "from api_key_manager import APIKeyManager"
echo ""
echo "async def create_key():"
echo " pool = await asyncpg.create_pool("
echo " host='unicorn-postgresql',"
echo " port=5432,"
echo " user='unicorn',"
echo " password='unicorn',"
echo " database='unicorn_db'"
echo " )"
echo " manager = APIKeyManager(pool)"
echo " await manager.initialize_table()"
echo " result = await manager.create_api_key("
echo " user_id='admin@example.com',"
echo " key_name='CLI Generated Key',"
echo " expires_in_days=90"
echo " )"
echo " print(f\"API Key: {result['api_key']}\")"
echo " print(f\"Key ID: {result['key_id']}\")"
echo " print(f\"Prefix: {result['key_prefix']}\")"
echo " await pool.close()"
echo ""
echo "asyncio.run(create_key())"
echo "PYTHON"
echo ""
echo "=========================================="