Use ServerManager's passfile in connect() credential gate.#9810
Use ServerManager's passfile in connect() credential gate.#9810m000 wants to merge 2 commits intopgadmin-org:masterfrom
Conversation
WalkthroughReordered credential fallback in psycopg3 connection: Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@web/pgadmin/utils/driver/psycopg3/connection.py`:
- Around line 317-320: The current logic creates a Path for kwargs['passfile']
and calls passfile.read_text() without validating that the value is non-empty
and points to a regular readable file; update the code around the passfile
handling so that if kwargs['passfile'] is an empty string it is treated as None,
then verify passfile.exists() and passfile.is_file() before calling
passfile.read_text(), and wrap the read_text() call in a try/except that catches
IsADirectoryError, FileNotFoundError, PermissionError, and UnicodeDecodeError
(and convert or re-raise them as a clear connection error or log appropriately)
so that reading failures do not propagate uncaught from the code that sets the
password variable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 340f95c2-cfcc-42e7-a15f-f262c72b2620
📒 Files selected for processing (1)
web/pgadmin/utils/driver/psycopg3/connection.py
50a03d5 to
7c9be2d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@web/pgadmin/utils/driver/psycopg3/connection.py`:
- Around line 316-317: The code constructs Path(kwargs['passfile']) whenever the
'passfile' key exists, which raises TypeError if its value is None; change the
guard so you only call Path(...) when the retrieved value is not None/empty
(e.g., use val = kwargs.get('passfile') and then passfile = Path(val) only if
val is truthy), ensuring the variable passfile remains None otherwise so
downstream exception handling around connect() or the passfile logic can run
safely.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a364471d-0bf2-4720-9580-b8a79cbfc2c3
📒 Files selected for processing (1)
web/pgadmin/utils/driver/psycopg3/connection.py
|
Thanks @adityatoshniwal |
asheshv
left a comment
There was a problem hiding this comment.
The check-python-style CI job is failing because line 326 is 80 characters (limit is 79):
web/pgadmin/utils/driver/psycopg3/connection.py:326: [E501] line too long (80 > 79 characters)
Please replace the .format() call with an f-string to fix it:
current_app.logger.warning(
f"Using the first of two specified"
f" passfiles: {passfile!r}, {passfile_kwarg!r}"
)6e982c6 to
a8f5043
Compare
|
@asheshv fixed. Thanks! I also updated the PR text to match the changes. |
|
Thanks @m000 — the cleanup makes sense, the kwarg
Also, the title's a bit stale now — something like "Use ServerManager's passfile in connect() credential gate" fits the final shape better. |
asheshv
left a comment
There was a problem hiding this comment.
Please fix this comment: #9810 (comment)
Checking for a passfile is done by using the value returned by the ServerManager, which will also be used when constructing the connection string. An extra check is added, to warn if passfile is also provided as a kwarg to Connection::connect() and differs from the passfile picked up by ServerManager.
Done. You're right, ignoring passexec may come as a surprise to some users. Not sure how common this config may be, so I also added an extra warning message for the case. Let me know if anything else is needed. |
Checking for a passfile is done by using the value returned by the ServerManager, which will also be used when constructing the connection string.
The ServerManager supplied passfile is preferred over (a) any specified passexec, (b) any passfile kwarg passed to Connection::connect(). This is probably the desired behaviour, but it is still different from the previous version. For this, warnings are emitted when:
Use PassFile to retrieve a password when one is not retrieved by other means. The PassFile setting was already passed to connect() but was never read.Summary by CodeRabbit