Skip to content

🐛 Generate API base URL by active product ⚠️ #7619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

giancarloromeo
Copy link
Contributor

@giancarloromeo giancarloromeo commented Apr 30, 2025

What do these changes do?

This pull request fixes the API base URL generation by replacing hardcoded values with dynamically constructed URLs based on the request's forwarded host information. It also centralizes host extraction logic via a new generator function and adds tests to verify the correct URL format.

  • Updates API key creation flow to generate the correct base URL.
  • Introduces the iter_origins helper for consistent host extraction.

Related issue/s

How to test

cd services/web/server
pytest -vv --pdb tests/unit/with_dbs/01/test_api_keys.py

Dev-ops

Remove DIRECTOR_V2_PUBLIC_API_BASE_URL env vars

@giancarloromeo giancarloromeo added a:webserver issue related to the webserver service a:director-v2 issue related with the director-v2 service labels Apr 30, 2025
@giancarloromeo giancarloromeo added this to the Pauwel Kwak milestone Apr 30, 2025
@giancarloromeo giancarloromeo self-assigned this Apr 30, 2025
Copy link

codecov bot commented Apr 30, 2025

Codecov Report

Attention: Patch coverage is 83.09859% with 12 lines in your changes missing coverage. Please review.

Project coverage is 87.61%. Comparing base (5ff7809) to head (52088bf).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7619      +/-   ##
==========================================
- Coverage   87.66%   87.61%   -0.06%     
==========================================
  Files        1794     1806      +12     
  Lines       69341    69686     +345     
  Branches     1136     1190      +54     
==========================================
+ Hits        60790    61054     +264     
- Misses       8241     8307      +66     
- Partials      310      325      +15     
Flag Coverage Δ
integrationtests 64.73% <78.37%> (-0.04%) ⬇️
unittests 86.82% <81.69%> (-0.06%) ⬇️
Components Coverage Δ
api ∅ <ø> (∅)
pkg_aws_library 93.92% <ø> (ø)
pkg_dask_task_models_library 98.48% <ø> (ø)
pkg_models_library 92.88% <100.00%> (+0.01%) ⬆️
pkg_notifications_library 85.26% <ø> (ø)
pkg_postgres_database 88.41% <ø> (ø)
pkg_service_integration 69.92% <ø> (ø)
pkg_service_library 72.88% <ø> (ø)
pkg_settings_library 90.90% <ø> (ø)
pkg_simcore_sdk 85.66% <ø> (+0.11%) ⬆️
agent 96.46% <ø> (ø)
api_server 92.50% <ø> (ø)
autoscaling 96.08% <ø> (ø)
catalog 92.64% <ø> (ø)
clusters_keeper 99.25% <ø> (ø)
dask_sidecar 89.88% <ø> (ø)
datcore_adapter 98.12% <ø> (ø)
director 76.80% <ø> (ø)
director_v2 91.19% <100.00%> (+<0.01%) ⬆️
dynamic_scheduler 96.76% <ø> (ø)
dynamic_sidecar 90.15% <ø> (ø)
efs_guardian 89.79% <ø> (ø)
invitations 93.28% <ø> (ø)
payments 92.63% <ø> (ø)
resource_usage_tracker 89.02% <ø> (ø)
storage 87.49% <ø> (-0.15%) ⬇️
webclient ∅ <ø> (∅)
webserver 85.89% <100.00%> (+0.02%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ff7809...52088bf. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@giancarloromeo giancarloromeo requested a review from Copilot May 5, 2025 13:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request fixes the API base URL generation by replacing hardcoded values with dynamically constructed URLs based on the request's forwarded host information. It also centralizes host extraction logic via a new generator function and adds tests to verify the correct URL format.

  • Updates API key creation flow to generate the correct base URL.
  • Introduces the iter_originating_hosts helper for consistent host extraction.
  • Adds unit tests to validate the new API base URL behavior.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
services/web/server/tests/unit/with_dbs/01/test_api_keys.py Updated test to verify new API base URL generation with the forwarded host header.
services/web/server/src/simcore_service_webserver/utils_aiohttp.py Added the iter_originating_hosts generator to streamline host extraction.
services/web/server/src/simcore_service_webserver/utils.py Introduced is_ip_address to assist in host validation.
services/web/server/src/simcore_service_webserver/products/_web_middlewares.py Replaced manual host lookup with iter_originating_hosts for consistency.
services/web/server/src/simcore_service_webserver/api_keys/_controller/rest.py Updated _get_api_base_url to build the API URL dynamically and removed the hardcoded URL.

@ITISFoundation ITISFoundation deleted a comment from Copilot AI May 5, 2025
@giancarloromeo giancarloromeo marked this pull request as ready for review May 5, 2025 14:30
Copy link
Member

@pcrespov pcrespov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! thx

Copy link
Contributor

@GitHK GitHK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice, thanks!

@giancarloromeo giancarloromeo added 🤖-automerge marks PR as ready to be merged for Mergify and removed 🤖-do-not-merge (optional) blocks Mergify from merging the PR labels May 14, 2025
@giancarloromeo giancarloromeo enabled auto-merge (squash) May 14, 2025 09:18
@giancarloromeo giancarloromeo added 🤖-automerge marks PR as ready to be merged for Mergify and removed 🤖-automerge marks PR as ready to be merged for Mergify labels May 14, 2025
@giancarloromeo
Copy link
Contributor Author

@Mergifyio: Queue

@giancarloromeo giancarloromeo modified the milestones: Pauwel Kwak, Bazinga! May 14, 2025
Copy link
Member

@mrnicegyu11 mrnicegyu11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi: only checked ops-related things (env vars etc), thanks a lot!

@giancarloromeo
Copy link
Contributor Author

fyi: only checked ops-related things (env vars etc), thanks a lot!

Sure, that's enough!

@giancarloromeo giancarloromeo merged commit c552e46 into ITISFoundation:master May 14, 2025
93 of 95 checks passed
@giancarloromeo giancarloromeo deleted the fix-api-base-url-generation branch May 14, 2025 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖-automerge marks PR as ready to be merged for Mergify a:webserver issue related to the webserver service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API endpoint is wrong api-keys: DIRECTOR_V2_PUBLIC_API_BASE_URL does not account for active product!
8 participants