Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
da7c291
Fix Flask-RESTX API routing and implement automated testing
d-ulker Sep 4, 2025
3ee58db
Fix API Routing and Add Automated Testing
deepsource-autofix[bot] Sep 4, 2025
5cedf0c
Address code review comments: environment-based logging, remove emoji…
d-ulker Sep 4, 2025
6c82ee5
Address code review comments on fix-api-routing branch
d-ulker Sep 4, 2025
40eb6e4
Fix API Routing and Add Automated Testing
deepsource-autofix[bot] Sep 4, 2025
7612373
Add missing docstrings to resolve PY-D0003 linting issues
d-ulker Sep 4, 2025
47484b2
Fix PYL-W0612: Prefix unused Health class with underscore
d-ulker Sep 4, 2025
46aa0e3
Fix PYL-W0125 linting issues: remove constant if False: conditions in…
d-ulker Sep 4, 2025
4a4a3f3
Fix API Routing and Add Automated Testing
deepsource-autofix[bot] Sep 4, 2025
cf134a4
Add missing docstrings to resolve PY-D0003 linting issues
d-ulker Sep 4, 2025
13039b8
Fix API Routing and Add Automated Testing
deepsource-autofix[bot] Sep 4, 2025
b87e7e1
Apply code review fixes for API routing
d-ulker Sep 4, 2025
7a28037
Fix PYL-W1203 linting issues: convert f-string logging to lazy % form…
d-ulker Sep 4, 2025
f6fdb30
Add missing class docstrings to resolve PY-D0002 linting issues
d-ulker Sep 4, 2025
67cedf8
Fix PR review comments: error handler re-raise, env var log level, re…
d-ulker Sep 4, 2025
6d69210
Fix error logging in secure_api_server.py: replace logger.error with …
d-ulker Sep 4, 2025
a56ed6b
Fix Copilot AI code review issues
d-ulker Sep 4, 2025
0ba1600
Fix FLK-E501 linting issues: break long logger lines into multiple lines
d-ulker Sep 5, 2025
0202d41
feat: address 22 nitpick comments for code quality improvements
d-ulker Sep 5, 2025
b9b5a5c
Fix API Routing and Add Automated Testing
deepsource-autofix[bot] Sep 5, 2025
b58b2a5
fix: address additional code quality issues
d-ulker Sep 5, 2025
93cd12a
fix: address additional code quality issues from Sourcery AI
d-ulker Sep 5, 2025
c0a01c7
fix: address additional code quality issues from Gemini Code Assist
d-ulker Sep 5, 2025
d1218dc
fix: critical bug - variable used before assignment in secure_api_ser…
d-ulker Sep 5, 2025
f534055
fix: address additional code quality issues from detailed feedback
d-ulker Sep 5, 2025
ac4476c
fix: comprehensive code quality improvements from detailed feedback
d-ulker Sep 5, 2025
b3a5035
Fix API Routing and Add Automated Testing
deepsource-autofix[bot] Sep 5, 2025
98da7d8
fix: final code quality improvements from detailed feedback
d-ulker Sep 5, 2025
cbe88c9
Fix API Routing and Add Automated Testing
deepsource-autofix[bot] Sep 5, 2025
bcae431
Fix test setup and Flask-RESTX static methods
d-ulker Sep 5, 2025
c31dfa3
Merge branch 'fix-api-routing' of https://github.com/uelkerd/SAMO--DL…
d-ulker Sep 5, 2025
68cb5d9
fix: Address 22 nitpick comments for code quality improvements
d-ulker Sep 5, 2025
acd49cb
Fix API Routing and Add Automated Testing
deepsource-autofix[bot] Sep 5, 2025
fcc5c13
fix: Address line length violations (FLK-E501)
d-ulker Sep 5, 2025
0c0b119
fix: Address remaining f-string loggings (FLK-E501)
d-ulker Sep 5, 2025
8f5e802
feat: Address all 22 nitpick comments for code quality improvements
d-ulker Sep 5, 2025
73e8acf
fix: Address additional linting issues from feedback
d-ulker Sep 5, 2025
c95aaf2
fix: Remove fragile lambda-based decorators and fix import-time sys.e…
d-ulker Sep 5, 2025
ab09455
Fix API Routing and Add Automated Testing
deepsource-autofix[bot] Sep 5, 2025
0bb0cc3
Update tests/unit/test_api_routing.py
d-ulker Sep 5, 2025
ba05b57
fix: Remove problematic patches that prevent Flask-RESTX route regist…
d-ulker Sep 5, 2025
1b50165
fix: Address remaining linting issues
d-ulker Sep 5, 2025
68c48d6
fix: Remove unused exception variables in deployment/secure_api_serve…
d-ulker Sep 5, 2025
d29f2c5
fix: Address final linting issues
d-ulker Sep 5, 2025
f414457
fix: Resolve merge conflict in deployment/secure_api_server.py
d-ulker Sep 5, 2025
b948ddd
fix: Address code review nitpicks in test_api_routing.py
cursoragent Sep 6, 2025
9e67fc3
Fix API Routing and Add Automated Testing
deepsource-autofix[bot] Sep 6, 2025
7a404f5
fix: Address comprehensive code review nitpicks across 39 issues
cursoragent Sep 6, 2025
87d7272
fix: Address additional code review nitpicks - 3 more issues
cursoragent Sep 6, 2025
ba68944
Merge remote-tracking branch 'origin/fix-api-routing' into fix-api-ro…
cursoragent Sep 6, 2025
e7a1b7f
fix: Address comprehensive code review nitpicks - 26 additional issues
cursoragent Sep 6, 2025
0976399
fix: Correct indentation in test_docs_error.py
cursoragent Sep 6, 2025
e47c5ad
fix: Resolve undefined variable linting errors
cursoragent Sep 6, 2025
f0e2a6d
fix: Resolve remaining functools undefined variable errors
cursoragent Sep 6, 2025
cf7883f
security: Fix binding to all interfaces vulnerability (BAN-B104)
cursoragent Sep 6, 2025
b2692b3
security: Fix hardcoded temporary directory vulnerability (BAN-B108)
cursoragent Sep 6, 2025
1a63232
Fix API Routing and Add Automated Testing
deepsource-autofix[bot] Sep 6, 2025
17e705b
Add missing add_to_blacklist/add_to_whitelist methods to TokenBucketR…
cursoragent Sep 8, 2025
ddd7b60
nitpick: Address 9 code quality improvements
cursoragent Sep 8, 2025
31f95e6
nitpick: Address additional 4 code quality improvements
cursoragent Sep 8, 2025
e32102f
nitpick: Address 19 additional code quality improvements
cursoragent Sep 8, 2025
ad6e6a6
nitpick: Address 21 additional code quality improvements
cursoragent Sep 8, 2025
04b3c83
nitpick: Address 15 additional code quality improvements
cursoragent Sep 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions deployment/cloud-run/debug_api_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
print("✅ Flask imported successfully")
except Exception as e:
print(f"❌ Flask import failed: {e}")
sys.exit(1)
raise RuntimeError(f"Flask import failed: {e}") from e

try:
print("2. Importing Flask-RESTX...")
from flask_restx import Api, Resource, fields, Namespace
print("✅ Flask-RESTX imported successfully")
except Exception as e:
print(f"❌ Flask-RESTX import failed: {e}")
sys.exit(1)
raise RuntimeError(f"Flask-RESTX import failed: {e}") from e

try:
print("3. Creating Flask app...")
app = Flask(__name__)
print("✅ Flask app created successfully")
except Exception as e:
print(f"❌ Flask app creation failed: {e}")
sys.exit(1)
raise RuntimeError(f"Flask app creation failed: {e}") from e

try:
print("4. Creating API object...")
Expand All @@ -47,7 +47,7 @@
print(f"API object: {api}")
except Exception as e:
print(f"❌ API creation failed: {e}")
sys.exit(1)
raise RuntimeError(f"API creation failed: {e}") from e

try:
print("5. Testing API decorator...")
Expand All @@ -59,7 +59,7 @@ def test_handler(error):
print(f"❌ API decorator test failed: {e}")
print(f"API type at this point: {type(api)}")
print(f"API value at this point: {api}")
sys.exit(1)
raise RuntimeError(f"API decorator test failed: {e}") from e

try:
print("6. Testing namespace creation...")
Expand All @@ -68,7 +68,7 @@ def test_handler(error):
print("✅ Namespace test successful")
except Exception as e:
print(f"❌ Namespace test failed: {e}")
sys.exit(1)
raise RuntimeError(f"Namespace test failed: {e}") from e

print("🎉 All tests passed! The issue is not with basic Flask-RESTX functionality.")

Expand Down
4 changes: 2 additions & 2 deletions deployment/cloud-run/debug_errorhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
print("✅ Imports successful")
except Exception as e:
print(f"❌ Import failed: {e}")
sys.exit(1)
raise RuntimeError(f"Import failed: {e}") from e

try:
app = Flask(__name__)
Expand All @@ -30,7 +30,7 @@
print("✅ API object created successfully")
except Exception as e:
print(f"❌ API creation failed: {e}")
sys.exit(1)
raise RuntimeError(f"API creation failed: {e}") from e

# Let's inspect the API object in detail
print(f"\n🔍 API object details:")
Expand Down
17 changes: 10 additions & 7 deletions deployment/cloud-run/debug_errorhandler_detailed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
Detailed debug script to understand the errorhandler issue
"""

# ruff: noqa: T201

import os
os.environ['ADMIN_API_KEY'] = 'test123'
if __name__ == '__main__':
os.environ.setdefault('ADMIN_API_KEY', 'test-admin-key-123')

print("🔍 Starting detailed errorhandler debug...")

Expand All @@ -14,15 +17,15 @@
print("✅ Imports successful")
except Exception as e:
print(f"❌ Import failed: {e}")
exit(1)
raise RuntimeError(f"Import failed: {e}") from e

try:
app = Flask(__name__)
api = Api(app, version='1.0.0', title='Test')
print("✅ API object created")
except Exception as e:
print(f"❌ API creation failed: {e}")
exit(1)
raise RuntimeError(f"API creation failed: {e}") from e

# Let's inspect the API object in detail
print(f"\n🔍 API object details:")
Expand Down Expand Up @@ -56,7 +59,7 @@
print(f"Bound call result: {type(result2)} - {result2}")

# Let's check if there's a difference
print(f"\nResults are the same: {result == result2}")
print(f"\nSame object: {result is result2}")

except Exception as e:
print(f"❌ errorhandler testing failed: {e}")
Expand All @@ -70,9 +73,9 @@

# Let's check if there's a version issue
try:
import flask_restx
print(f"\n🔍 Flask-RESTX version: {flask_restx.__version__}")
print(f"Flask version: {flask.__version__}")
from importlib.metadata import version
print(f"\n🔍 Flask-RESTX version: {version('flask-restx')}")
print(f"Flask version: {version('flask')}")
except Exception as e:
print(f"❌ Could not get versions: {e}")

Expand Down
18 changes: 15 additions & 3 deletions deployment/cloud-run/docs_blueprint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
from pathlib import Path
from flask import Blueprint, Response, jsonify, render_template, g


Expand All @@ -11,13 +12,24 @@
def serve_openapi_spec():
"""Serve OpenAPI spec for Swagger UI with safe path validation."""
# Restrict spec path to a safe directory
allowed_dir = os.path.abspath(os.environ.get('OPENAPI_ALLOWED_DIR', '/app'))
allowed_dir = Path(os.environ.get('OPENAPI_ALLOWED_DIR', '/app')).resolve()
spec_path = os.environ.get('OPENAPI_SPEC_PATH', '/app/openapi.yaml')
abs_spec_path = os.path.abspath(spec_path)
abs_spec_path = Path(spec_path).resolve()

try:
# Validate that the spec path is within the allowed directory
if os.path.commonpath([abs_spec_path, allowed_dir]) != allowed_dir:
# Use robust containment check compatible with older Python versions
try:
is_contained = abs_spec_path.is_relative_to(allowed_dir)
except AttributeError:
# Fallback for Python < 3.9
try:
is_contained = (os.path.commonpath([str(allowed_dir), str(abs_spec_path)]) == \
str(allowed_dir))
except ValueError:
is_contained = False

if abs_spec_path.parent != allowed_dir and not is_contained:
return jsonify({'error': 'Invalid OpenAPI spec path'}), 400

with open(abs_spec_path, 'r', encoding='utf-8') as f:
Expand Down
3 changes: 1 addition & 2 deletions deployment/cloud-run/health_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import os
import sys
import time
import signal
import logging
Expand Down Expand Up @@ -60,7 +59,7 @@ def _graceful_shutdown(self, signum, frame):
else:
logger.info("Graceful shutdown completed successfully")

sys.exit(0)
raise SystemExit(0)

def get_system_metrics(self) -> Dict[str, float]:
"""Get current system resource usage"""
Expand Down
18 changes: 10 additions & 8 deletions deployment/cloud-run/minimal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import os
os.environ['ADMIN_API_KEY'] = 'test123'
os.environ.setdefault('ADMIN_API_KEY', os.environ.get('TEST_ADMIN_API_KEY', 'test-admin-key-123'))

print("🔍 Starting minimal API setup test...")

Expand All @@ -15,15 +15,15 @@
print("✅ Imports successful")
except Exception as e:
print(f"❌ Imports failed: {e}")
exit(1)
raise RuntimeError(f"Imports failed: {e}") from e

try:
print("2. Creating Flask app...")
app = Flask(__name__)
print("✅ Flask app created")
except Exception as e:
print(f"❌ Flask app creation failed: {e}")
exit(1)
raise RuntimeError(f"Flask app creation failed: {e}") from e

try:
print("3. Creating API object...")
Expand All @@ -36,7 +36,7 @@
print(f"✅ API object created: {type(api)}")
except Exception as e:
print(f"❌ API creation failed: {e}")
exit(1)
raise RuntimeError(f"API creation failed: {e}") from e

try:
print("4. Creating namespace...")
Expand All @@ -45,7 +45,7 @@
print("✅ Namespace added")
except Exception as e:
print(f"❌ Namespace creation failed: {e}")
exit(1)
raise RuntimeError(f"Namespace creation failed: {e}") from e

try:
print("5. Creating model...")
Expand All @@ -55,18 +55,20 @@
print("✅ Model created")
except Exception as e:
print(f"❌ Model creation failed: {e}")
exit(1)
raise RuntimeError(f"Model creation failed: {e}") from e

try:
print("6. Testing errorhandler...")
@api.errorhandler(429)
from werkzeug.exceptions import TooManyRequests
@api.errorhandler(TooManyRequests)
def test_handler(error):
"""Return a canned 429 for debug validation."""
return {"error": "test"}, 429
print("✅ Error handler created")
except Exception as e:
print(f"❌ Error handler creation failed: {e}")
print(f"API type at this point: {type(api)}")
print(f"API errorhandler type: {type(api.errorhandler)}")
exit(1)
raise RuntimeError(f"Error handler creation failed: {e}") from e

print("🎉 All tests passed!")
Loading
Loading