This commit is contained in:
johnpccd 2025-05-25 13:59:03 +02:00
parent efe4445639
commit 107ade464d
5 changed files with 0 additions and 352 deletions

View File

@ -1,49 +0,0 @@
#!/usr/bin/env python3
"""
Debug script to test API key hashing with deployment configuration
"""
import os
import sys
import hmac
import hashlib
def hash_api_key_manual(api_key: str, secret: str) -> str:
"""
Manual implementation of API key hashing to test
"""
return hmac.new(
secret.encode(),
api_key.encode(),
hashlib.sha256
).hexdigest()
def test_api_key_hashing():
"""Test API key hashing with different secrets"""
# The new API key from your seeding output
test_api_key = "uZBVUEku.7332d85bf6cf2618ad76bca46c2f8125"
# Test with different possible secrets
secrets_to_test = [
"super-secret-key-for-development-only", # Default from config.py
"development-secret-key-do-not-use-in-production", # Your .env value
]
print("API Key Hashing Debug")
print("=" * 60)
print(f"Test API Key: {test_api_key}")
print()
for secret in secrets_to_test:
hashed_key = hash_api_key_manual(test_api_key, secret)
print(f"Secret: {secret}")
print(f"Hash: {hashed_key}")
print("-" * 60)
print()
print("The deployment should be using one of these hashes in the database.")
print("Check your Cloud Run environment variables to confirm which secret is being used.")
if __name__ == "__main__":
test_api_key_hashing()

View File

@ -1,58 +0,0 @@
#!/usr/bin/env python3
"""
Debug script to test VectorDatabaseService initialization
"""
import os
import sys
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
print("Environment variables:")
print(f"QDRANT_HOST: {os.getenv('QDRANT_HOST')}")
print(f"QDRANT_PORT: {os.getenv('QDRANT_PORT')}")
print(f"QDRANT_HTTPS: {os.getenv('QDRANT_HTTPS')}")
print(f"QDRANT_PREFER_GRPC: {os.getenv('QDRANT_PREFER_GRPC')}")
# Import and check settings
from src.config.config import settings
print("\nSettings values:")
print(f"settings.QDRANT_HOST: {settings.QDRANT_HOST}")
print(f"settings.QDRANT_PORT: {settings.QDRANT_PORT}")
print(f"settings.QDRANT_HTTPS: {settings.QDRANT_HTTPS}")
print(f"settings.QDRANT_PREFER_GRPC: {settings.QDRANT_PREFER_GRPC}")
# Test VectorDatabaseService initialization step by step
print("\nTesting VectorDatabaseService initialization step by step...")
try:
from qdrant_client import QdrantClient
# Test direct QdrantClient creation
print("Creating QdrantClient directly...")
client = QdrantClient(
host=settings.QDRANT_HOST,
port=settings.QDRANT_PORT,
api_key=settings.QDRANT_API_KEY,
prefer_grpc=settings.QDRANT_PREFER_GRPC,
https=settings.QDRANT_HTTPS
)
print("QdrantClient created successfully")
# Test get_collections (this is what fails in _ensure_collection_exists)
print("Testing get_collections...")
collections = client.get_collections()
print(f"Collections retrieved: {[col.name for col in collections.collections]}")
# Now test full VectorDatabaseService
print("\nTesting full VectorDatabaseService...")
from src.services.vector_db import VectorDatabaseService
vector_db = VectorDatabaseService()
print("VectorDatabaseService created successfully")
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()

View File

@ -1,167 +0,0 @@
#!/bin/bash
# Setup Local Environment Script
# This script extracts configuration from terraform and sets up local development
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
TERRAFORM_DIR="$PROJECT_ROOT/deployment/terraform"
echo "Setting up local development environment..."
# Check if terraform directory exists
if [ ! -d "$TERRAFORM_DIR" ]; then
echo "Error: Terraform directory not found at $TERRAFORM_DIR"
exit 1
fi
# Change to terraform directory
cd "$TERRAFORM_DIR"
# Check if terraform state exists
if [ ! -f "terraform.tfstate" ]; then
echo "Error: Terraform state not found. Please run 'terraform apply' first."
exit 1
fi
echo "Extracting configuration from terraform..."
# Get terraform outputs
QDRANT_HOST=$(terraform output -raw vector_db_vm_external_ip 2>/dev/null || echo "")
QDRANT_PORT="6333"
FIRESTORE_PROJECT_ID=$(terraform output -raw firestore_database_id 2>/dev/null | cut -d'/' -f2 || echo "")
GCS_BUCKET_NAME=$(terraform output -raw storage_bucket_name 2>/dev/null || echo "")
if [ -z "$QDRANT_HOST" ]; then
echo "Error: Could not extract Qdrant host from terraform outputs"
exit 1
fi
echo "Configuration extracted:"
echo " Qdrant Host: $QDRANT_HOST"
echo " Qdrant Port: $QDRANT_PORT"
echo " Firestore Project: $FIRESTORE_PROJECT_ID"
echo " GCS Bucket: $GCS_BUCKET_NAME"
# Go back to project root
cd "$PROJECT_ROOT"
# Update start_dev.sh with extracted values
echo "Updating start_dev.sh..."
cat > start_dev.sh << EOF
#!/bin/bash
# Development startup script for Sereact API
# This script sets the environment variables and starts the application
# Auto-generated by deployment/scripts/setup_local_env.sh
# Activate virtual environment
source venv/Scripts/activate
# Set environment variables from deployed infrastructure
export QDRANT_HOST=$QDRANT_HOST
export QDRANT_PORT=$QDRANT_PORT
export FIRESTORE_PROJECT_ID=$FIRESTORE_PROJECT_ID
export GCS_BUCKET_NAME=$GCS_BUCKET_NAME
export ENVIRONMENT=development
# Start the application
echo "Starting Sereact API with deployed infrastructure..."
echo "Qdrant endpoint: http://\$QDRANT_HOST:\$QDRANT_PORT"
echo "Firestore project: \$FIRESTORE_PROJECT_ID"
echo "GCS bucket: \$GCS_BUCKET_NAME"
echo "API will be available at: http://localhost:8000"
echo "API documentation: http://localhost:8000/docs"
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
EOF
chmod +x start_dev.sh
# Update docker-compose.yml with extracted values
echo "Updating docker-compose.yml..."
cat > docker-compose.yml << EOF
version: '3.8'
services:
api:
build: .
ports:
- "8000:8000"
volumes:
- .:/app
- \${GOOGLE_APPLICATION_CREDENTIALS:-./firestore-credentials.json}:/app/firestore-credentials.json:ro
environment:
- PYTHONUNBUFFERED=1
- ENVIRONMENT=development
- FIRESTORE_CREDENTIALS_FILE=/app/firestore-credentials.json
- GOOGLE_APPLICATION_CREDENTIALS=/app/firestore-credentials.json
- FIRESTORE_PROJECT_ID=\${FIRESTORE_PROJECT_ID:-$FIRESTORE_PROJECT_ID}
- QDRANT_HOST=$QDRANT_HOST
- QDRANT_PORT=$QDRANT_PORT
- GCS_BUCKET_NAME=$GCS_BUCKET_NAME
command: uvicorn main:app --host 0.0.0.0 --port 8000 --reload
EOF
# Update test script
echo "Updating test_qdrant_connection.py..."
cat > test_qdrant_connection.py << EOF
#!/usr/bin/env python3
"""
Simple test script to verify Qdrant connection
Auto-generated by deployment/scripts/setup_local_env.sh
"""
import os
import sys
from src.services.vector_db import VectorDatabaseService
def test_qdrant_connection():
"""Test the connection to Qdrant"""
# Set environment variables from deployed infrastructure
os.environ['QDRANT_HOST'] = '$QDRANT_HOST'
os.environ['QDRANT_PORT'] = '$QDRANT_PORT'
try:
print("Testing Qdrant connection...")
print(f"Host: {os.environ['QDRANT_HOST']}")
print(f"Port: {os.environ['QDRANT_PORT']}")
# Initialize the service
vector_db = VectorDatabaseService()
# Test health check
is_healthy = vector_db.health_check()
print(f"Health check: {'✓ PASSED' if is_healthy else '✗ FAILED'}")
# Get collection info
collection_info = vector_db.get_collection_info()
print(f"Collection info: {collection_info}")
print("\n✓ Qdrant connection test PASSED!")
return True
except Exception as e:
print(f"\n✗ Qdrant connection test FAILED: {e}")
return False
if __name__ == "__main__":
success = test_qdrant_connection()
sys.exit(0 if success else 1)
EOF
echo ""
echo "✓ Local development environment setup complete!"
echo ""
echo "You can now:"
echo " 1. Run './start_dev.sh' to start the API with deployed infrastructure"
echo " 2. Run 'docker-compose up' to use Docker with deployed Qdrant"
echo " 3. Run 'python test_qdrant_connection.py' to test Qdrant connection"
echo ""
echo "All configuration has been automatically extracted from your terraform deployment."

View File

@ -1,21 +0,0 @@
#!/usr/bin/env python3
import requests
import json
# Test the images API
def test_images_api():
base_url = "http://localhost:8000"
# First, let's check if we need to bootstrap or if there are existing API keys
try:
# Try to get images without API key first to see the error
response = requests.get(f"{base_url}/api/v1/images")
print(f"Images API without auth: {response.status_code}")
print(f"Response: {response.text[:200]}...")
except Exception as e:
print(f"Error testing images API: {e}")
if __name__ == "__main__":
test_images_api()

View File

@ -1,57 +0,0 @@
#!/usr/bin/env python3
"""
Simple test script to verify Qdrant connection
Auto-generated by deployment/scripts/setup_local_env.sh
"""
import os
import sys
from src.services.vector_db import VectorDatabaseService
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
def test_qdrant_connection():
"""Test the connection to Qdrant"""
# Set environment variables from deployed infrastructure
# os.environ['QDRANT_HOST'] = '34.171.134.17'
# os.environ['QDRANT_PORT'] = '6333'
# os.environ['QDRANT_HTTPS'] = 'false' # Explicitly disable HTTPS
# os.environ['QDRANT_PREFER_GRPC'] = 'false' # Explicitly disable gRPC
try:
print("Testing Qdrant connection...")
# print(f"Host: {os.environ['QDRANT_HOST']}")
# print(f"Port: {os.environ['QDRANT_PORT']}")
# print(f"HTTPS: {os.environ['QDRANT_HTTPS']}")
# print(f"gRPC: {os.environ['QDRANT_PREFER_GRPC']}")
# Initialize the service with explicit parameters to ensure HTTP is used
vector_db = VectorDatabaseService(
host=os.environ['QDRANT_HOST'],
port=int(os.environ['QDRANT_PORT']),
prefer_grpc=False,
https=False
)
# Test health check
is_healthy = vector_db.health_check()
print(f"Health check: {'✓ PASSED' if is_healthy else '✗ FAILED'}")
# Get collection info
collection_info = vector_db.get_collection_info()
print(f"Collection info: {collection_info}")
print("\n✓ Qdrant connection test PASSED!")
return True
except Exception as e:
print(f"\n✗ Qdrant connection test FAILED: {e}")
return False
if __name__ == "__main__":
success = test_qdrant_connection()
sys.exit(0 if success else 1)