feat: add MONGO_URI environment variable support (#253)#256
Open
minhpham1810 wants to merge 4 commits intoelixir-cloud-aai:devfrom
Open
feat: add MONGO_URI environment variable support (#253)#256minhpham1810 wants to merge 4 commits intoelixir-cloud-aai:devfrom
minhpham1810 wants to merge 4 commits intoelixir-cloud-aai:devfrom
Conversation
Add support for a MONGO_URI environment variable that, when set, is used as the complete MongoDB connection string, taking precedence over individual component variables (MONGO_HOST, MONGO_PORT, MONGO_USERNAME, MONGO_PASSWORD, MONGO_DBNAME). This enables advanced connection features such as replica sets, SRV records, TLS options, and URIs from external secret managers. A warning is logged when MONGO_URI is set alongside individual variables to help users avoid configuration confusion. Full backward compatibility is maintained.
Reviewer's GuideAdds support for a MONGO_URI environment variable that, when set and non-empty, is used as the complete MongoDB connection string with precedence over individual MongoDB env vars and config, along with tests, logging, and documentation/template updates describing this behavior. Sequence diagram for Flask app initialization with MONGO_URI supportsequenceDiagram
participant Env as Environment
participant App as FlaskApp
participant Reg as register_mongodb
participant Mongo as PyMongo
App->>Reg: _create_mongo_client(app, host, port, db)
Reg->>Env: get MONGO_URI
Env-->>Reg: MONGO_URI value or null
alt MONGO_URI set and non-empty
Reg->>Env: get MONGO_HOST, MONGO_PORT,
Env-->>Reg: individual env values
Reg->>Reg: build list of set individual vars
alt any individual vars set
Reg->>App: logger.warning(MONGO_URI overrides individual vars)
end
Reg->>App: set app.config[MONGO_URI]
Reg->>Mongo: create PyMongo(app)
Mongo-->>Reg: PyMongo client
Reg->>App: logger.info(registered via MONGO_URI)
Reg-->>App: PyMongo client
else MONGO_URI not set or empty
Reg->>Env: get MONGO_USERNAME, MONGO_PASSWORD,
Env-->>Reg: individual env values
Reg->>Reg: build connection URI from env or config
Reg->>Mongo: create PyMongo(app)
Mongo-->>Reg: PyMongo client
Reg-->>App: PyMongo client
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
_create_mongo_client, consider normalizingMONGO_URIand the individual env vars (e.g., using.strip()and treating empty strings as unset) so that whitespace/empty-string values don’t unintentionally trigger URI usage or get included in the "ignored" warning list.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_create_mongo_client`, consider normalizing `MONGO_URI` and the individual env vars (e.g., using `.strip()` and treating empty strings as unset) so that whitespace/empty-string values don’t unintentionally trigger URI usage or get included in the "ignored" warning list.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- add INFO log after casbin enforcer registration in register_access_control.py - add INFO log after permission spec registration in register_access_control.py - add INFO log after access-control registration in foca.py - add focused log-flow unit test in test_register_access_control.py - update access-control tests to assert emitted logs via stderr capture in test_foca.py - replace deprecated importlib.resources path usage with files/as_file in config.py and register_access_control.py - suppress known third-party deprecation noise in pytest config in setup.cfg Suggested PR title Add readable access-control setup logs and clean up deprecation/test noise Suggested PR description Summary This PR implements issue elixir-cloud-aai#250 by adding readable confirmation logs for the access-control setup flow, then updates tests and warning handling so CI output is reliable and low-noise. What changed 1. Access-control setup logging - Added log confirming enforcer registration in register_access_control.py. - Added log confirming permission spec registration in register_access_control.py. - Added top-level log confirming access-control registration completion in foca.py. 2. Test updates - Added a focused unit test to validate setup-step logs in test_register_access_control.py. - Updated access-control assertions in test_foca.py to use stderr capture, matching current project logging behavior. 3. Deprecation cleanup - Replaced deprecated importlib.resources path usage with files/as_file in: - config.py - register_access_control.py - Added pytest warning filters for known external deprecations in setup.cfg. Why - Improves operator visibility during bootstrap by clearly signaling successful access-control setup steps. - Prevents flaky/false-negative log assertions caused by logger capture differences. - Reduces warning noise from dependency internals so real regressions are easier to spot. Validation - Ran: pytest -q test_foca.py - Result: 15 passed Issue - Closes elixir-cloud-aai#250
…d-aai#253)" This reverts commit 6e19fe8.
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.
Description
Add support for a MONGO_URI environment variable that, when set, is used as the complete MongoDB connection string, taking precedence over individual component variables (MONGO_HOST, MONGO_PORT, MONGO_USERNAME, MONGO_PASSWORD, MONGO_DBNAME). This enables advanced connection features such as replica sets, SRV records, TLS options, and URIs from external secret managers.
A warning is logged when MONGO_URI is set alongside individual variables to help users avoid configuration confusion. Full backward compatibility is maintained.
Fixes #253
Type of change
Please delete options that are not relevant.
Checklist:
Summary by Sourcery
Add support for configuring the MongoDB client via a single MONGO_URI environment variable that takes precedence over individual MongoDB settings while preserving existing behavior as a fallback.
New Features:
Enhancements:
Documentation:
Tests: