mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-18 20:09:25 +00:00
fix: remove extra Exception from debug.py
This commit is contained in:
parent
05450ae7dc
commit
50ad84d27d
1 changed files with 16 additions and 22 deletions
|
|
@ -11,7 +11,7 @@ router = APIRouter()
|
||||||
async def debug_deployment():
|
async def debug_deployment():
|
||||||
"""Debug endpoint for deployment verification and isolation testing"""
|
"""Debug endpoint for deployment verification and isolation testing"""
|
||||||
learnhouse_config = get_learnhouse_config()
|
learnhouse_config = get_learnhouse_config()
|
||||||
|
|
||||||
# Parse database host safely
|
# Parse database host safely
|
||||||
db_host = "unknown"
|
db_host = "unknown"
|
||||||
db_user = "unknown"
|
db_user = "unknown"
|
||||||
|
|
@ -27,7 +27,7 @@ async def debug_deployment():
|
||||||
user_parts = auth_parts[1].split(':')
|
user_parts = auth_parts[1].split(':')
|
||||||
if len(user_parts) > 0:
|
if len(user_parts) > 0:
|
||||||
db_user = user_parts[0]
|
db_user = user_parts[0]
|
||||||
|
|
||||||
# Extract host and database name
|
# Extract host and database name
|
||||||
host_parts = auth_host_parts[1].split('/')
|
host_parts = auth_host_parts[1].split('/')
|
||||||
if len(host_parts) > 0:
|
if len(host_parts) > 0:
|
||||||
|
|
@ -36,7 +36,7 @@ async def debug_deployment():
|
||||||
db_name = host_parts[1]
|
db_name = host_parts[1]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Parse redis host safely
|
# Parse redis host safely
|
||||||
redis_host = "unknown"
|
redis_host = "unknown"
|
||||||
redis_db = "unknown"
|
redis_db = "unknown"
|
||||||
|
|
@ -51,7 +51,7 @@ async def debug_deployment():
|
||||||
redis_db = host_parts[1].split('/')[1]
|
redis_db = host_parts[1].split('/')[1]
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Get hostname information
|
# Get hostname information
|
||||||
import socket
|
import socket
|
||||||
hostname = "unknown"
|
hostname = "unknown"
|
||||||
|
|
@ -59,7 +59,7 @@ async def debug_deployment():
|
||||||
hostname = socket.gethostname()
|
hostname = socket.gethostname()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Get process and container info
|
# Get process and container info
|
||||||
container_id = "unknown"
|
container_id = "unknown"
|
||||||
try:
|
try:
|
||||||
|
|
@ -71,7 +71,7 @@ async def debug_deployment():
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"deployment_name": os.environ.get('DEPLOYMENT_NAME', 'NOT_SET'),
|
"deployment_name": os.environ.get('DEPLOYMENT_NAME', 'NOT_SET'),
|
||||||
"hostname": hostname,
|
"hostname": hostname,
|
||||||
|
|
@ -104,12 +104,12 @@ async def debug_urls(request: Request):
|
||||||
"edu.adradviser.ro", # LIVE domain
|
"edu.adradviser.ro", # LIVE domain
|
||||||
"adr-lms.whitex.cloud" # DEV domain
|
"adr-lms.whitex.cloud" # DEV domain
|
||||||
]
|
]
|
||||||
|
|
||||||
# Add any additional domains from environment variables
|
# Add any additional domains from environment variables
|
||||||
current_domain = os.environ.get('NEXT_PUBLIC_LEARNHOUSE_DOMAIN', '')
|
current_domain = os.environ.get('NEXT_PUBLIC_LEARNHOUSE_DOMAIN', '')
|
||||||
if current_domain and current_domain not in known_domains:
|
if current_domain and current_domain not in known_domains:
|
||||||
known_domains.append(current_domain)
|
known_domains.append(current_domain)
|
||||||
|
|
||||||
# Build patterns for all domains to detect cross-contamination
|
# Build patterns for all domains to detect cross-contamination
|
||||||
patterns = []
|
patterns = []
|
||||||
for domain in known_domains:
|
for domain in known_domains:
|
||||||
|
|
@ -122,7 +122,7 @@ async def debug_urls(request: Request):
|
||||||
f"fetch\\(\"https://{domain}",
|
f"fetch\\(\"https://{domain}",
|
||||||
f"fetch\\(\"http://{domain}",
|
f"fetch\\(\"http://{domain}",
|
||||||
])
|
])
|
||||||
|
|
||||||
# Add general patterns for NextAuth configuration
|
# Add general patterns for NextAuth configuration
|
||||||
patterns.extend([
|
patterns.extend([
|
||||||
"\"/api/auth/session\"",
|
"\"/api/auth/session\"",
|
||||||
|
|
@ -134,10 +134,10 @@ async def debug_urls(request: Request):
|
||||||
"NEXTAUTH_URL=\"[^\"]*\"",
|
"NEXTAUTH_URL=\"[^\"]*\"",
|
||||||
"NEXTAUTH_URL='[^']*'"
|
"NEXTAUTH_URL='[^']*'"
|
||||||
])
|
])
|
||||||
|
|
||||||
all_urls = []
|
all_urls = []
|
||||||
domain_matches = {domain: [] for domain in known_domains}
|
domain_matches = {domain: [] for domain in known_domains}
|
||||||
|
|
||||||
# Search for URLs in JS files
|
# Search for URLs in JS files
|
||||||
for pattern in patterns:
|
for pattern in patterns:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
|
|
@ -147,13 +147,13 @@ async def debug_urls(request: Request):
|
||||||
if result.stdout.strip():
|
if result.stdout.strip():
|
||||||
found_urls = list(set(result.stdout.strip().split('\n')))
|
found_urls = list(set(result.stdout.strip().split('\n')))
|
||||||
all_urls.extend(found_urls)
|
all_urls.extend(found_urls)
|
||||||
|
|
||||||
# Categorize URLs by domain
|
# Categorize URLs by domain
|
||||||
for url in found_urls:
|
for url in found_urls:
|
||||||
for domain in known_domains:
|
for domain in known_domains:
|
||||||
if domain in url:
|
if domain in url:
|
||||||
domain_matches[domain].append(url)
|
domain_matches[domain].append(url)
|
||||||
|
|
||||||
# Look for NextAuth configuration
|
# Look for NextAuth configuration
|
||||||
auth_configs = []
|
auth_configs = []
|
||||||
try:
|
try:
|
||||||
|
|
@ -165,7 +165,7 @@ async def debug_urls(request: Request):
|
||||||
auth_configs = list(set(auth_result.stdout.strip().split('\n')))
|
auth_configs = list(set(auth_result.stdout.strip().split('\n')))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Gather environment variable information
|
# Gather environment variable information
|
||||||
env_vars = {
|
env_vars = {
|
||||||
"NEXT_PUBLIC_LEARNHOUSE_DOMAIN": os.environ.get('NEXT_PUBLIC_LEARNHOUSE_DOMAIN', 'NOT_SET'),
|
"NEXT_PUBLIC_LEARNHOUSE_DOMAIN": os.environ.get('NEXT_PUBLIC_LEARNHOUSE_DOMAIN', 'NOT_SET'),
|
||||||
|
|
@ -175,14 +175,14 @@ async def debug_urls(request: Request):
|
||||||
"NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN": os.environ.get('NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN', 'NOT_SET'),
|
"NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN": os.environ.get('NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN', 'NOT_SET'),
|
||||||
"LEARNHOUSE_COOKIE_DOMAIN": os.environ.get('LEARNHOUSE_COOKIE_DOMAIN', 'NOT_SET')
|
"LEARNHOUSE_COOKIE_DOMAIN": os.environ.get('LEARNHOUSE_COOKIE_DOMAIN', 'NOT_SET')
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the top domain from an environment variable or extract from current domain
|
# Get the top domain from an environment variable or extract from current domain
|
||||||
top_domain = os.environ.get('NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN', '')
|
top_domain = os.environ.get('NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN', '')
|
||||||
if not top_domain and current_domain:
|
if not top_domain and current_domain:
|
||||||
parts = current_domain.split('.')
|
parts = current_domain.split('.')
|
||||||
if len(parts) >= 2:
|
if len(parts) >= 2:
|
||||||
top_domain = '.'.join(parts[-2:])
|
top_domain = '.'.join(parts[-2:])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"detected_hardcoded_urls": all_urls,
|
"detected_hardcoded_urls": all_urls,
|
||||||
"domain_specific_matches": domain_matches,
|
"domain_specific_matches": domain_matches,
|
||||||
|
|
@ -201,9 +201,3 @@ async def debug_urls(request: Request):
|
||||||
"message": "Could not scan for hardcoded URLs",
|
"message": "Could not scan for hardcoded URLs",
|
||||||
"deployment_name": os.environ.get('DEPLOYMENT_NAME', 'NOT_SET')
|
"deployment_name": os.environ.get('DEPLOYMENT_NAME', 'NOT_SET')
|
||||||
}
|
}
|
||||||
except Exception as e:
|
|
||||||
return {
|
|
||||||
"error": str(e),
|
|
||||||
"message": "Could not scan for hardcoded URLs",
|
|
||||||
"deployment_name": os.environ.get('DEPLOYMENT_NAME', 'NOT_SET')
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue