Skip to content

Commit ec3b548

Browse files
Added support for passing connection details as variables in the passexec command. #6794
1 parent 2813d82 commit ec3b548

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

docs/en_US/server_dialog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ Use the fields in the *Advanced* tab to configure a connection:
205205
command will be used as the SQL password. This may be useful when the password
206206
should be generated as a transient authorization token instead of providing a
207207
password when connecting in `PAM authentication <https://www.postgresql.org/docs/current/auth-pam.html>`_ scenarios.
208+
You can pass server hostname, port, and DB username to the password exec command as variable by providing placeholders
209+
like ``%DB_HOSTNAME%``, ``%DB_PORT%`` and ``%DB_USERNAME%`` which will be replaced with the server connection information.
208210
* Use the *Password exec expiration* field to specify a maximum age, in seconds,
209211
of the password generated with a *Password exec command*. If not specified,
210212
the password will not expire until your pgAdmin session does.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ def update(self, server):
8383
self.db_res = server.db_res
8484
self.name = server.name
8585
self.passexec = \
86-
PasswordExec(server.passexec_cmd, server.passexec_expiration) \
86+
PasswordExec(server.passexec_cmd, server.host, server.port,
87+
server.username, server.passexec_expiration) \
8788
if server.passexec_cmd else None
8889
self.service = server.service
8990

web/pgadmin/utils/passexec.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ class PasswordExec:
2020

2121
lock = Lock()
2222

23-
def __init__(self, cmd, expiration_seconds=None, timeout=60):
24-
self.cmd = str(cmd)
23+
def __init__(self, cmd, host, port, username, expiration_seconds=None,
24+
timeout=60):
25+
cmd = str(cmd).replace('%DB_HOSTNAME%', host)
26+
cmd = cmd.replace('%DB_PORT%', str(port))
27+
cmd = cmd.replace('%DB_USERNAME%', username)
28+
self.cmd = cmd
2529
self.expiration_seconds = int(expiration_seconds) \
2630
if expiration_seconds is not None else None
2731
self.timeout = int(timeout)

0 commit comments

Comments
 (0)