Add support for passing connection details as placeholders in the passexec command. #6794

Added a fix where electron app menu was not refreshing when node selection changed.
This commit is contained in:
Pravesh Sharma 2024-11-29 17:54:07 +05:30 committed by GitHub
parent 8876c4241f
commit 6810fa6ce6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 9 deletions

View File

@ -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 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 should be generated as a transient authorization token instead of providing a
password when connecting in `PAM authentication <https://www.postgresql.org/docs/current/auth-pam.html>`_ scenarios. password when connecting in `PAM authentication <https://www.postgresql.org/docs/current/auth-pam.html>`_ 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, * 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, of the password generated with a *Password exec command*. If not specified,
the password will not expire until your pgAdmin session does. the password will not expire until your pgAdmin session does.

View File

@ -70,12 +70,6 @@ export default class MainMenuFactory {
return new MenuItem({type: 'separator', label, priority}); 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) { static createMenuItem(options) {
return new MenuItem({...options, callback: () => { return new MenuItem({...options, callback: () => {
// Some callbacks registered in 'callbacks' check and call specifiec callback function // 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 // set the context menu as well
pgAdmin.Browser.BrowserContextMenu = MainMenuFactory.getDynamicMenu('context', item, itemData, true); pgAdmin.Browser.BrowserContextMenu = MainMenuFactory.getDynamicMenu('context', item, itemData, true);
window.electronUI?.setMenus(MainMenuFactory.toElectron());
pgAdmin.Browser.Events.trigger('pgadmin:refresh-app-menu'); pgAdmin.Browser.Events.trigger('pgadmin:refresh-app-menu');
} }

View File

@ -83,7 +83,8 @@ class ServerManager(object):
self.db_res = server.db_res self.db_res = server.db_res
self.name = server.name self.name = server.name
self.passexec = \ 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 if server.passexec_cmd else None
self.service = server.service self.service = server.service

View File

@ -20,8 +20,12 @@ class PasswordExec:
lock = Lock() lock = Lock()
def __init__(self, cmd, expiration_seconds=None, timeout=60): def __init__(self, cmd, host, port, username, expiration_seconds=None,
self.cmd = str(cmd) 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) \ self.expiration_seconds = int(expiration_seconds) \
if expiration_seconds is not None else None if expiration_seconds is not None else None
self.timeout = int(timeout) self.timeout = int(timeout)