image_management_api/debug_api_key_deployment.py

49 lines
1.4 KiB
Python

#!/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()