Skip to content

Commit 55cf4b6

Browse files
committed
Read password from PassFile when connecting.
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.
1 parent d8a078a commit 55cf4b6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import secrets
1818
import datetime
1919
import asyncio
20-
import copy
2120
from collections import deque
21+
from pathlib import Path
2222
import psycopg
2323
from flask import g, current_app
2424
from flask_babel import gettext
@@ -281,7 +281,6 @@ def connect(self, **kwargs):
281281
password, encpass, is_update_password = \
282282
self._check_user_password(kwargs)
283283

284-
passfile = kwargs['passfile'] if 'passfile' in kwargs else None
285284
tunnel_password = kwargs['tunnel_password'] if 'tunnel_password' in \
286285
kwargs else ''
287286

@@ -313,6 +312,17 @@ def connect(self, **kwargs):
313312
if is_error:
314313
return False, errmsg
315314

315+
# Retrieve password from passfile if one has not been set yet.
316+
passfile = Path(kwargs['passfile']) if 'passfile' in kwargs else None
317+
if not password and passfile:
318+
try:
319+
password = passfile.read_text(encoding='utf-8').strip()
320+
except (OSError, UnicodeDecodeError) as e:
321+
return False, \
322+
_(
323+
"Failed to read PassFile.\nError: {0}"\
324+
).format(str(e)
325+
316326
# If no password credential is found then connect request might
317327
# come from Query tool, ViewData grid, debugger etc tools.
318328
# we will check for pgpass file availability from connection manager

0 commit comments

Comments
 (0)