refactor password assignment logic

This commit is contained in:
Divyansh Singh 2023-06-15 22:54:06 +05:30
parent a9386b7a87
commit b7423c488e
2 changed files with 5 additions and 2 deletions

View File

@ -72,7 +72,7 @@ def restore_single_database(
): # pragma: no cover
'''
Given (among other things) an archive name, a database hook name, the hostname,
port, username and password as connection params, and a configured database
port, username and password as connection params, and a configured database
configuration dict, restore that database from the archive.
'''
logger.info(

View File

@ -30,7 +30,10 @@ def make_extra_environment(database, restore_connection_params=None):
extra = dict()
try:
extra['PGPASSWORD'] = restore_connection_params.get('password') or database['restore_password'] or database['password']
if restore_connection_params:
extra['PGPASSWORD'] = restore_connection_params.get('password') or database.get('restore_password', database['password'])
else:
extra['PGPASSWORD'] = database['password']
except (AttributeError, KeyError):
pass