feat: enhance construct_database_url_from_env_vars with port, SSL, and RFC 3986 encoding [sc-541344]#97
Draft
mateo-di wants to merge 1 commit into
Draft
Conversation
…d RFC 3986 encoding Add DATABASE_PORT, DATABASE_SSL_MODE, and DATABASE_SSL_ROOT_CERT support to the URL construction helper. Switch from quote_plus to quote(safe='') for correct RFC 3986 percent-encoding per PostgreSQL URI spec. Fix DATABASE_SCHEMA not being URL-encoded (existing bug). Build query params as a list for cleaner multi-param handling. All new env vars are optional — fully backward compatible. Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enhance the
construct_database_url_from_env_vars()helper to supportDATABASE_PORT,DATABASE_SSL_MODE, andDATABASE_SSL_ROOT_CERTas optional env vars. Switch fromquote_plustoquote(safe='')for correct RFC 3986 percent-encoding per PostgreSQL URI spec. FixDATABASE_SCHEMAnot being URL-encoded.Story: sc-541344
Related: CartoDB/cloud-native#23679 (short-term entrypoint.sh fix)
What Changed
Added:
DATABASE_PORTsupport — separate port env var (ignored if host already contains:port)DATABASE_SSL_MODEsupport — appended as?sslmode=...query paramDATABASE_SSL_ROOT_CERTsupport — appended as&sslrootcert=...query parampgHgsh@gh4#Mj$!password)Modified:
urllib.parse.quote_plus()tourllib.parse.quote(safe='')— correct RFC 3986 percent-encoding per PostgreSQL connection URI specDATABASE_SCHEMAis now URL-encoded (was previously inserted raw — existing bug)Removed:
Architectural Context
EAD: N/A - small change
Architectural Decisions Made:
DATABASE_*) — CARTO'sLITELLM_DATABASE_*prefix is a deployment concern handled byentrypoint.shquote(safe='')instead ofquote_plus()— PostgreSQL URIs follow RFC 3986 (percent-encoding), not HTML form encodingsslrootcertpath is NOT URL-encoded — it's a filesystem path consumed by libpq, not a URI componentReview Focus Areas
Critical areas (require thorough review):
litellm/proxy/utils.py— the enhanced function logic, especially port detection and query param buildingtests/test_litellm/proxy/test_proxy_cli.py— new test coverage for all scenariosSafe to skip: Docstring changes
Deployment Impact
Note: All new env vars are optional. Existing deployments that don't set
DATABASE_PORT,DATABASE_SSL_MODE, orDATABASE_SSL_ROOT_CERTproduce exactly the same URL as before. The encoding change (quote_plus→quote) only differs for spaces (which are extremely rare in DB credentials).Migration & Breaking Changes
Security Considerations
Performance Impact
Tests
test_proxy_cli.pypass)Dependencies
How to Validate
poetry run python -m pytest tests/test_litellm/proxy/test_proxy_cli.py -k "test_construct_database_url" -vvAll 6 URL construction tests should pass (1 existing + 5 new).
AI-Generated Code Notice
quotevsquote_plus), port detection logicChecklist