Skip to content

Commit c1ffe0d

Browse files
committed
Clarify passfile logic in Connection::connect().
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.
1 parent 5db808c commit c1ffe0d

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

web/pgadmin/utils/driver/psycopg3/connection.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import secrets
1818
import datetime
1919
import asyncio
20-
import copy
2120
from collections import deque
2221
import psycopg
2322
from flask import g, current_app
@@ -281,7 +280,6 @@ def connect(self, **kwargs):
281280
password, encpass, is_update_password = \
282281
self._check_user_password(kwargs)
283282

284-
passfile = kwargs['passfile'] if 'passfile' in kwargs else None
285283
tunnel_password = kwargs['tunnel_password'] if 'tunnel_password' in \
286284
kwargs else ''
287285

@@ -313,14 +311,22 @@ def connect(self, **kwargs):
313311
if is_error:
314312
return False, errmsg
315313

316-
# If no password credential is found then connect request might
317-
# come from Query tool, ViewData grid, debugger etc tools.
318-
# we will check for pgpass file availability from connection manager
319-
# if it's present then we will use it
320-
if not password and not encpass and not passfile:
321-
passfile = manager.get_connection_param_value('passfile')
322-
if manager.passexec:
323-
password = manager.passexec.get()
314+
# If no password credential is found then connect request might come
315+
# from Query tool, ViewData grid, debugger, etc. In that case, fall
316+
# back to using the password returned from manager.passexec.
317+
passfile = manager.get_connection_param_value('passfile')
318+
if not password and not encpass and not passfile and manager.passexec:
319+
password = manager.passexec.get()
320+
321+
# create_connection_string() automatically picks up the passfile from
322+
# connection parameters. Warn if that differs from the passfile kwarg.
323+
passfile_kwarg = kwargs.get('passfile', None)
324+
if passfile_kwarg and passfile_kwarg != passfile:
325+
current_app.logger.warning(
326+
"Using the first of two specified passfiles: {!r}, {!r}".format(
327+
passfile, passfile_kwarg
328+
)
329+
)
324330

325331
try:
326332
database = self.db

0 commit comments

Comments
 (0)