mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Set PGPASSWORD environment variable from the process executor before running
the external utility.
This commit is contained in:
parent
2da3a710a1
commit
ca62825c90
@ -289,10 +289,17 @@ def execute(configs):
|
||||
# Update start time
|
||||
update_configs(args)
|
||||
|
||||
if args['pid'] in os.environ:
|
||||
os.environ['PGPASSWORD'] = os.environ[args['pid']]
|
||||
|
||||
process = Popen(
|
||||
command, stdout=PIPE, stderr=PIPE, stdin=PIPE,
|
||||
shell=(os.name == 'nt'), close_fds=(os.name != 'nt')
|
||||
)
|
||||
try:
|
||||
del(os.environ['PGPASSWORD'])
|
||||
except:
|
||||
pass
|
||||
|
||||
# Attach the stream to the process logger, and start logging.
|
||||
process_stdout.attach_process_stream(process, process.stdout)
|
||||
|
@ -174,7 +174,7 @@ class BackupMessage(IProcessDesc):
|
||||
res += ' ' + arg
|
||||
elif replace_next:
|
||||
res += ' "' + cgi.escape(
|
||||
os.path.join('<STORAGE_DIR>', self.bfile)
|
||||
self.bfile
|
||||
).encode('ascii', 'xmlcharrefreplace') + '"'
|
||||
else:
|
||||
if arg == '--file':
|
||||
@ -299,6 +299,7 @@ def create_backup_job(sid):
|
||||
),
|
||||
cmd=utility, args=args
|
||||
)
|
||||
manager.export_password_env(p.id)
|
||||
p.start()
|
||||
jid = p.id
|
||||
except Exception as e:
|
||||
@ -443,6 +444,7 @@ def create_backup_objects_job(sid):
|
||||
BACKUP.OBJECT, sid, data['file'], database=data['database']
|
||||
),
|
||||
cmd=utility, args=args)
|
||||
manager.export_password_env(p.id)
|
||||
p.start()
|
||||
jid = p.id
|
||||
except Exception as e:
|
||||
|
@ -120,9 +120,9 @@ class RestoreMessage(IProcessDesc):
|
||||
idx += 1
|
||||
|
||||
if no_args > 1:
|
||||
res += ' "' + cgi.escape(
|
||||
os.path.join('<STORAGE_DIR>', self.bfile) + '"'
|
||||
).encode('ascii', 'xmlcharrefreplace')
|
||||
res += ' "' + cgi.escape(self.bfile).encode(
|
||||
'ascii', 'xmlcharrefreplace'
|
||||
) + '"'
|
||||
|
||||
res += '</i></div>'
|
||||
|
||||
@ -300,6 +300,7 @@ def create_restore_job(sid):
|
||||
desc=RestoreMessage(sid, data['file']),
|
||||
cmd=utility, args=args
|
||||
)
|
||||
manager.export_password_env(p.id)
|
||||
p.start()
|
||||
jid = p.id
|
||||
except Exception as e:
|
||||
|
@ -14,7 +14,9 @@ object.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import config
|
||||
import os
|
||||
import random
|
||||
import select
|
||||
|
||||
import psycopg2
|
||||
import psycopg2.extras
|
||||
@ -24,12 +26,10 @@ from flask import g, current_app, session
|
||||
from flask.ext.babel import gettext
|
||||
from flask.ext.security import current_user
|
||||
|
||||
from ..abstract import BaseDriver, BaseConnection
|
||||
import config
|
||||
from pgadmin.model import Server, User
|
||||
from pgadmin.utils.crypto import decrypt
|
||||
import random
|
||||
import select
|
||||
|
||||
from ..abstract import BaseDriver, BaseConnection
|
||||
from .keywords import ScanKeyword
|
||||
|
||||
|
||||
@ -1236,6 +1236,12 @@ WHERE db.oid = {0}""".format(did))
|
||||
|
||||
return None
|
||||
|
||||
def export_password_env(self, env):
|
||||
if self.password:
|
||||
password = decrypt(
|
||||
self.password, current_user.password
|
||||
).decode()
|
||||
os.environ[str(env)] = password
|
||||
|
||||
|
||||
class Driver(BaseDriver):
|
||||
|
Loading…
Reference in New Issue
Block a user