diff --git a/docs/en_US/server_dialog.rst b/docs/en_US/server_dialog.rst index 4ec406f66..5ba850149 100644 --- a/docs/en_US/server_dialog.rst +++ b/docs/en_US/server_dialog.rst @@ -205,6 +205,9 @@ Use the fields in the *Advanced* tab to configure a connection: command will be used as the SQL password. This may be useful when the password should be generated as a transient authorization token instead of providing a password when connecting in `PAM authentication `_ scenarios. + You can pass server hostname, port and DB username to the password exec command as variable by providing placeholders + like ``%HOST%``, ``%PORT%`` and ``%USERNAME%`` which will be replace with the server connection information. + Example: ``/path/to/script --hostnmae %HOST% --port %PORT% --username %USERNAME%`` * Use the *Password exec expiration* field to specify a maximum age, in seconds, of the password generated with a *Password exec command*. If not specified, the password will not expire until your pgAdmin session does. diff --git a/web/pgadmin/browser/static/js/MainMenuFactory.js b/web/pgadmin/browser/static/js/MainMenuFactory.js index 6894ed354..655acab15 100644 --- a/web/pgadmin/browser/static/js/MainMenuFactory.js +++ b/web/pgadmin/browser/static/js/MainMenuFactory.js @@ -70,12 +70,6 @@ export default class MainMenuFactory { return new MenuItem({type: 'separator', label, priority}); } - static refreshMainMenuItems(menu, menuItems) { - menu.setMenuItems(menuItems); - window.electronUI?.setMenus(MainMenuFactory.toElectron()); - pgAdmin.Browser.Events.trigger('pgadmin:refresh-menu-item', pgAdmin.Browser.MainMenus); - } - static createMenuItem(options) { return new MenuItem({...options, callback: () => { // Some callbacks registered in 'callbacks' check and call specifiec callback function @@ -128,6 +122,8 @@ export default class MainMenuFactory { // set the context menu as well pgAdmin.Browser.BrowserContextMenu = MainMenuFactory.getDynamicMenu('context', item, itemData, true); + window.electronUI?.setMenus(MainMenuFactory.toElectron()); + pgAdmin.Browser.Events.trigger('pgadmin:refresh-app-menu'); } diff --git a/web/pgadmin/utils/driver/psycopg3/server_manager.py b/web/pgadmin/utils/driver/psycopg3/server_manager.py index 456d8898f..dc451fc7e 100644 --- a/web/pgadmin/utils/driver/psycopg3/server_manager.py +++ b/web/pgadmin/utils/driver/psycopg3/server_manager.py @@ -83,7 +83,8 @@ class ServerManager(object): self.db_res = server.db_res self.name = server.name self.passexec = \ - PasswordExec(server.passexec_cmd, server.passexec_expiration) \ + PasswordExec(server.passexec_cmd, server.host, server.port, + server.username, server.passexec_expiration) \ if server.passexec_cmd else None self.service = server.service diff --git a/web/pgadmin/utils/passexec.py b/web/pgadmin/utils/passexec.py index e52203a8e..189b15c7d 100644 --- a/web/pgadmin/utils/passexec.py +++ b/web/pgadmin/utils/passexec.py @@ -20,8 +20,12 @@ class PasswordExec: lock = Lock() - def __init__(self, cmd, expiration_seconds=None, timeout=60): - self.cmd = str(cmd) + def __init__(self, cmd, host, port, username, expiration_seconds=None, + timeout=60): + cmd = str(cmd).replace('%HOSTNAME%', host) + cmd = cmd.replace('%PORT%', str(port)) + cmd = cmd.replace('%USERNAME%', username) + self.cmd = cmd self.expiration_seconds = int(expiration_seconds) \ if expiration_seconds is not None else None self.timeout = int(timeout)